alexiscreuzot / SwiftyGif

High performance GIF engine
MIT License
2.02k stars 212 forks source link

Support for Gif without no kCGImagePropertyGIFDictionary #111

Closed billypchan closed 5 years ago

billypchan commented 5 years ago

Hi Alexis, Thanks for this great library! I have a suggestion for the case that the GIF has no kCGImagePropertyGIFDictionary, for example: not_animated

When I load this image, I got an exception when calling try UIImage(gifName: gifName). Here is my workaround to make it loaded as a normal UIImage:

extension UIImageView {
    func setGif(gifName: String, gifManager: SwiftyGifManager) throws {
        do {
            let gifImage = try UIImage(gifName: gifName)
            setGifImage(gifImage, manager: gifManager, loopCount: -1)
        } catch let error {
            print("Error : \(error.localizedDescription)")

            if let gifImage = UIImage(named: "\(gifName).gif") {
                image = gifImage
            } else {
                throw MyGifParseError.retryUIImageInitFail
            }
        }
    }
}

enum MyGifParseError: Error {
    case retryUIImageInitFail
}
alexiscreuzot commented 5 years ago

I guess this is fixed with your last pull request as I see no_property_dictionary.gif is displayed correctly. Closing