Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get first frame of gif
extension UIImage {
// first frame of gif
class func firstFrame(gif url: URL) -> UIImage? {
guard let data = try? Data(contentsOf: url) as CFData else {
return nil
}
guard let source = CGImageSourceCreateWithData(data, nil) else {
return nil
}
guard let cgimage = CGImageSourceCreateImageAtIndex(source, 0, nil) else {
return nil
}
let image = UIImage(cgImage: cgimage)
return image
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment