Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A thread safe, performant, feature rich image fetcher

License

NotificationsYou must be signed in to change notification settings

Ghost-Notes/PINRemoteImage

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fast, non-deadlocking parallel image downloader and cache for iOS

CocoaPods compatibleCarthage compatibleBuild status

PINRemoteImageManager is an image downloading, processing and caching manager. It uses the concept of download and processing tasks to ensure that even if multiple calls to download or process an image are made, it only occurs one time (unless an item is no longer in the cache). PINRemoteImageManager is backed byGCD and safe toaccess frommultiple threads simultaneously. It ensures that images are decoded off the main thread so that animation performance isn't affected. None of its exposed methods allow for synchronous access. However, it is optimized to call completions on the calling thread if an item is in its memory cache.

PINRemoteImage supports downloading many types of files. It, of course,supports bothPNGs andJPGs. It also supports decodingWebP images if Google's library is available. It even supportsGIFs andAnimated WebP via PINAnimatedImageView.

PINRemoteImage also has two methods to improve the experience of downloading images on slow network connections. The first is support forprogressive JPGs. This isn't any old support for progressive JPGs though: PINRemoteImage adds an attractive blur to progressive scans before returning them.

Progressive JPG with Blur

PINRemoteImageCategoryManager defines a protocol which UIView subclasses can implement and provide easy access toPINRemoteImageManager's methods. There arebuilt-in categories onUIImageView,PINAnimatedImageView andUIButton, and it's very easy to implement a new category. See [UIImageView+PINRemoteImage](/Pod/Classes/Image Categories/UIImageView+PINRemoteImage.h) of the existing categories for reference.

Download an image and set it on an image view:

Objective-C

UIImageView *imageView = [[UIImageViewalloc]init];[imageViewpin_setImageFromURL:[NSURLURLWithString:@"http://pinterest.com/kitten.jpg"]];

Swift

letimageView=UIImageView()imageView.pin_setImage(from:URL(string:"https://pinterest.com/kitten.jpg")!)

Download a progressive jpeg and get attractive blurred updates:

Objective-C

UIImageView *imageView = [[UIImageViewalloc]init];[imageViewsetPin_updateWithProgress:YES];[imageViewpin_setImageFromURL:[NSURLURLWithString:@"http://pinterest.com/progressiveKitten.jpg"]];

Swift

letimageView=UIImageView()imageView.pin_updateWithProgress=trueimageView.pin_setImage(from:URL(string:"https://pinterest.com/progressiveKitten.jpg")!)

Download a WebP file

Objective-C

UIImageView *imageView = [[UIImageViewalloc]init];[imageViewpin_setImageFromURL:[NSURLURLWithString:@"http://pinterest.com/googleKitten.webp"]];

Swift

letimageView=UIImageView()imageView.pin_setImage(from:URL(string:"https://pinterest.com/googleKitten.webp")!)

Download a GIF and display with PINAnimatedImageView

Objective-C

PINAnimatedImageView *animatedImageView = [[PINAnimatedImageViewalloc]init];[animatedImageViewpin_setImageFromURL:[NSURLURLWithString:@"http://pinterest.com/flyingKitten.gif"]];

Swift

letanimatedImageView=PINAnimatedImageView()animatedImageView.pin_setImage(from:URL(string:"http://pinterest.com/flyingKitten.gif")!)

Download and process an image

Objective-C

UIImageView *imageView = [[UIImageViewalloc]init];[self.imageViewpin_setImageFromURL:[NSURLURLWithString:@"https://i.pinimg.com/736x/5b/c6/c5/5bc6c5387ff6f104fd642f2b375efba3.jpg"]processorKey:@"rounded"processor:^UIImage *(PINRemoteImageManagerResult *result,NSUInteger *cost) {     CGSize targetSize =CGSizeMake(200,300);     CGRect imageRect =CGRectMake(0,0, targetSize.width, targetSize.height);UIGraphicsBeginImageContext(imageRect.size);     UIBezierPath *bezierPath = [UIBezierPathbezierPathWithRoundedRect:imageRectcornerRadius:7.0];     [bezierPathaddClip];     CGFloat sizeMultiplier =MAX(targetSize.width / result.image.size.width, targetSize.height / result.image.size.height);     CGRect drawRect =CGRectMake(0,0, result.image.size.width * sizeMultiplier, result.image.size.height * sizeMultiplier);if (CGRectGetMaxX(drawRect) >CGRectGetMaxX(imageRect)) {         drawRect.origin.x -= (CGRectGetMaxX(drawRect) -CGRectGetMaxX(imageRect)) /2.0;     }if (CGRectGetMaxY(drawRect) >CGRectGetMaxY(imageRect)) {         drawRect.origin.y -= (CGRectGetMaxY(drawRect) -CGRectGetMaxY(imageRect)) /2.0;     }     [result.imagedrawInRect:drawRect];     UIImage *processedImage =UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();return processedImage; }];

Swift

letimageView=FLAnimatedImageView()imageView.pin_setImage(from:URL(string:"https://i.pinimg.com/736x/5b/c6/c5/5bc6c5387ff6f104fd642f2b375efba3.jpg")!, processorKey:"rounded"){(result, unsafePointer)->UIImage?inguardlet image= result.imageelse{returnnil}letradius:CGFloat=7.0lettargetSize=CGSize(width:200, height:300)letimageRect=CGRect(x:0, y:0, width: targetSize.width, height: targetSize.height)UIGraphicsBeginImageContext(imageRect.size)letbezierPath=UIBezierPath(roundedRect: imageRect, cornerRadius: radius)    bezierPath.addClip()letwidthMultiplier:CGFloat= targetSize.width/ image.size.widthletheightMultiplier:CGFloat= targetSize.height/ image.size.heightletsizeMultiplier=max(widthMultiplier, heightMultiplier)vardrawRect=CGRect(x:0, y:0, width: image.size.width* sizeMultiplier, height: image.size.height* sizeMultiplier)if(drawRect.maxX> imageRect.maxX){        drawRect.origin.x-=(drawRect.maxX- imageRect.maxX)/2}if(drawRect.maxY> imageRect.maxY){        drawRect.origin.y-=(drawRect.maxY- imageRect.maxY)/2}    image.draw(in: drawRect)UIColor.red.setStroke()    bezierPath.lineWidth=5.0    bezierPath.stroke()letctx=UIGraphicsGetCurrentContext()    ctx?.setBlendMode(CGBlendMode.overlay)    ctx?.setAlpha(0.5)letlogo=UIImage(named:"white-pinterest-logo")    ctx?.scaleBy(x:1.0, y:-1.0)    ctx?.translateBy(x:0.0, y:-drawRect.size.height)iflet coreGraphicsImage= logo?.cgImage{        ctx?.draw(coreGraphicsImage, in:CGRect(x:90, y:10, width: logo!.size.width, height: logo!.size.height))}letprocessedImage=UIGraphicsGetImageFromCurrentImageContext()UIGraphicsEndImageContext()return processedImage}

Handle Authentication

Objective-C

[[PINRemoteImageManagersharedImageManager]setAuthenticationChallenge:^(NSURLSessionTask *task,NSURLAuthenticationChallenge *challenge, PINRemoteImageManagerAuthenticationChallengeCompletionHandler aCompletion) {aCompletion(NSURLSessionAuthChallengePerformDefaultHandling,nil)];

Swift

PINRemoteImageManager.shared().setAuthenticationChallenge{(task, challenge, completion)incompletion?(.performDefaultHandling,nil)}

Support for high resolution images

Currently there are two ways PINRemoteImage is supporting high resolution images:

  1. If the URL contains an_2x. or an_3x. postfix it will be automatically handled by PINRemoteImage and the resulting image will be returned at the right scale.
  2. If it's not possible to provide an URL with an_2x. or_3x. postfix, you can also handle it with a completion handler:
NSURL *url = ...;__weak UIImageView *weakImageView = self.imageView;[self.imageViewpin_setImageFromURL:urlcompletion:^(PINRemoteImageManagerResult * _Nonnull result) {  CGFloat scale = UIScreen.mainScreen.scale;if (scale >1.0) {    UIImage *image = result.image;    weakImageView.image = [UIImageimageWithCGImage:image.CGImagescale:scaleorientation:image.imageOrientation];    }}];

Set some limits

// cache is an instance of PINCache as long as you haven't overridden defaultImageCachePINCache *cache = (PINCache *)[[PINRemoteImageManager sharedImageManager] cache];// Max memory cost is based on number of pixels, we estimate the size of one hundred 600x600 images as our max memory image cache.[[cache memoryCache] setCostLimit:600 * [[UIScreen mainScreen] scale] * 600 * [[UIScreen mainScreen] scale] * 100];// ~50 MB[[cache diskCache] setByteLimit:50 * 1024 * 1024];// 30 days[[cache diskCache] setAgeLimit:60 * 60 * 24 * 30];

Installation

CocoaPods

AddPINRemoteImage to yourPodfile and runpod install.

If you'd like to use WebP images, addPINRemoteImage/WebP to yourPodfile and runpod install.

Carthage

Addgithub "pinterest/PINRemoteImage" to your Cartfile . SeeCarthage's readme for more information on integrating Carthage-built frameworks into your project.

Manually

Download the latest tag and drag thePod/Classes folder into your Xcode project. You must also manually link againstPINCache.

Install the docs by double clicking the.docset file underdocs/, or view them online atcocoadocs.org

Git Submodule

You can set up PINRemoteImage as a submodule of your repo instead of cloning and copying all the files into your repo. Add the submodule using the commands below and then follow the manual instructions above.

git submodule add https://github.com/pinterest/PINRemoteImage.gitgit submodule update --init

Requirements

PINRemoteImage requires iOS 12.0 or greater.

Contact

Garrett Moon@garrettmoonPinterest

License

Copyright 2015 Pinterest, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions and limitations under the License.

About

A thread safe, performant, feature rich image fetcher

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C95.1%
  • Swift3.2%
  • Other1.7%

[8]ページ先頭

©2009-2025 Movatter.jp