Skip to content

Instantly share code, notes, and snippets.

@bumaociyuan
Created May 4, 2018 08:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bumaociyuan/3b4d3da7144ae5baa28cd24b506d83ae to your computer and use it in GitHub Desktop.
Save bumaociyuan/3b4d3da7144ae5baa28cd24b506d83ae to your computer and use it in GitHub Desktop.
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