zadr / ClickToGIF

A NSOperation subclass that builds a UIImage out of the first frame of an animated GIF.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Download the first frame of an animated gif, instead of the full thing.

example usages:

	func example() {
		let url = NSBundle.mainBundle().URLForResource("puppy", withExtension: "gif")!
		let operation = CQIntroductoryGIFFrameOperation(URL: url)

		// note: `completionBlock` is also available from NSOperation, although it
		// works based off of KVO states, and will take an extra runloop or two to fire.
		operation.target = self
		operation.action = "gifProcessed:"

		NSOperationQueue.mainQueue().addOperation(operation)
	}

	@objc func gifProcessed(operation: CQIntroductoryGIFFrameOperation) {
		if let image = operation.introductoryFrameImageData {
			print("we have a still image of the first frame of an animated gif!")
		}
	}

or

	func example() {
		let url = NSBundle.mainBundle().URLForResource("puppy", withExtension: "gif")!
		let operation = CQIntroductoryGIFFrameOperation(URL: url)
		operation.completionBlock = {
			if let image = operation.introductoryFrameImageData {
				print("we have a still image of the first frame of an animated gif!")
			}
		}

		NSOperationQueue.mainQueue().addOperation(operation)
	}

(Or go straight to the code, in CQIntroductoryGIFFrameOperationHarness/CQIntroductoryGIFFrameOperation{.h, .m}.)

About

A NSOperation subclass that builds a UIImage out of the first frame of an animated GIF.

License:BSD 2-Clause "Simplified" License


Languages

Language:Objective-C 87.0%Language:Swift 13.0%