Scale GIF images
This commit is contained in:
parent
5db0d00ef3
commit
ad4babd25d
|
@ -1,4 +1,3 @@
|
|||
|
||||
Web Image
|
||||
=========
|
||||
|
||||
|
@ -9,6 +8,7 @@ It provides:
|
|||
- An UIImageView category adding web image and cache management to the Cocoa Touch framework
|
||||
- An asynchronous image downloader
|
||||
- An asynchronous memory + disk image caching with automatic cache expiration handling
|
||||
- Animated GIF support
|
||||
- A background image decompression
|
||||
- A guarantee that the same URL won't be downloaded several times
|
||||
- A guarantee that bogus URLs won't be retried again and again
|
||||
|
|
|
@ -183,7 +183,8 @@ static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
|
|||
{
|
||||
if ([data isGIF])
|
||||
{
|
||||
return [UIImage animatedGIFWithData:data];
|
||||
UIImage *image = [UIImage animatedGIFWithData:data];
|
||||
return [self scaledImageForKey:key image:image];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -14,21 +14,35 @@
|
|||
|
||||
inline UIImage *SDScaledImageForKey(NSString *key, UIImage *image)
|
||||
{
|
||||
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
|
||||
if ([image.images count] > 0)
|
||||
{
|
||||
CGFloat scale = 1.0;
|
||||
if (key.length >= 8)
|
||||
NSMutableArray *scaledImages = [NSMutableArray array];
|
||||
|
||||
for (UIImage *tempImage in image.images)
|
||||
{
|
||||
// Search @2x. at the end of the string, before a 3 to 4 extension length (only if key len is 8 or more @2x. + 4 len ext)
|
||||
NSRange range = [key rangeOfString:@"@2x." options:0 range:NSMakeRange(key.length - 8, 5)];
|
||||
if (range.location != NSNotFound)
|
||||
{
|
||||
scale = 2.0;
|
||||
}
|
||||
[scaledImages addObject:SDScaledImageForKey(key, tempImage)];
|
||||
}
|
||||
|
||||
UIImage *scaledImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:image.imageOrientation];
|
||||
image = scaledImage;
|
||||
|
||||
return [UIImage animatedImageWithImages:scaledImages duration:image.duration];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
|
||||
{
|
||||
CGFloat scale = 1.0;
|
||||
if (key.length >= 8)
|
||||
{
|
||||
// Search @2x. at the end of the string, before a 3 to 4 extension length (only if key len is 8 or more @2x. + 4 len ext)
|
||||
NSRange range = [key rangeOfString:@"@2x." options:0 range:NSMakeRange(key.length - 8, 5)];
|
||||
if (range.location != NSNotFound)
|
||||
{
|
||||
scale = 2.0;
|
||||
}
|
||||
}
|
||||
|
||||
UIImage *scaledImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:image.imageOrientation];
|
||||
image = scaledImage;
|
||||
}
|
||||
return image;
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue