pinterest / PINRemoteImage

A thread safe, performant, feature rich image fetcher
Apache License 2.0
4.01k stars 511 forks source link

Failure loading Giphy animted webp via url in PINAnimatedImageView #504

Closed chadpod closed 5 years ago

chadpod commented 5 years ago

I'm trying to load an animated webp from Giphy into a PINAnimatedImageView. It would download fine, but then fail to decode the image. I found myself having to add the following PIN_WEBP bit to PINAlternateRepresentationProvider:

@implementation PINAlternateRepresentationProvider

- (id)alternateRepresentationWithData:(NSData *)data options:(PINRemoteImageManagerDownloadOptions)options
{
    if ([data pin_isAnimatedGIF]) {
        return [[PINCachedAnimatedImage alloc] initWithAnimatedImageData:data];
    }
#if PIN_WEBP
    if ([data pin_isAnimatedWebP]) {
        return [[PINCachedAnimatedImage alloc] initWithAnimatedImageData:data];
    }
#endif
    return nil;
}

@end

to get it working. Can you point me in the right direction as to what I might be doing wrong or is this above change needed?

Here is how I am fetching the image:

        [self.imageView pin_setImageFromURL:url completion:^(PINRemoteImageManagerResult * _Nonnull result) {
            [self.imageView pin_updateUIWithRemoteImageManagerResult:result];
            [self.activityView stopAnimating];
        }];

Here is one of the animated webp urls:

https://media1.giphy.com/media/26gsxJfJgIyYXNoD6/100.webp
garrettmoon commented 5 years ago

Eeep, this is definitely a bug! I have a fix as part of another WebP bug in a branch I'm discussing with Google. I'm guessing I'll put up a PR soon, in the meantime here's the branch: https://github.com/pinterest/PINRemoteImage/tree/fixWebPAnimationBlending