Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always get the origin image #328

Closed
alfredcc opened this issue May 26, 2016 · 4 comments
Closed

Always get the origin image #328

alfredcc opened this issue May 26, 2016 · 4 comments
Labels

Comments

@alfredcc
Copy link

alfredcc commented May 26, 2016

Hi, thanks for the open source.
I use this below which version is 1.8.5, when I restart the App, I can get the round image
https://github.com/Limon-O-O/KingfisherExtension/blob/master/KingfisherExtension/UIImageView%2BExtension.swift#L22-#L50

But when I update the Kingfisher to the last version 2.4.1, and change code to this below. Then I restart the App, I always get the origin image(which is not cropped).

It seems that the cache system always store the origin image to disk.

func kfe_setRoundImageWithURLString(URLString: String?, cornerRadiusRatio: CGFloat? = nil, options: KingfisherOptionsInfo? = nil, progressBlock: ImageDownloaderProgressBlock? = nil) {

        guard let URLString = URLString, URL = NSURL(string: URLString) else {
            return
        }

        guard let image = KingfisherManager.sharedManager.cache.retrieveImageInMemoryCacheForKey(URLString) ?? KingfisherManager.sharedManager.cache.retrieveImageInDiskCacheForKey(URLString) else {

            KingfisherManager.sharedManager.downloader.downloadImageWithURL(URL, options: options, progressBlock: progressBlock) { (image, error, imageURL, originalData) -> () in

                if let image = image, originalData = originalData {

                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {

                        let roundedImage = image.kfe_roundWithCornerRadius(image.size.width * (cornerRadiusRatio ?? 0.5))

                        KingfisherManager.sharedManager.cache.storeImage(roundedImage, originalData: originalData, forKey: URLString, toDisk: false, completionHandler: {

                            self.kfe_setImageWithURLString(URLString)
                        })
                    }
                }
            }

            return
        }

        self.image = image
    }
@alfredcc alfredcc changed the title Always get the origion Always get the origin image May 26, 2016
@alfredcc
Copy link
Author

The only difference is

// version 1.8.5
func kfe_setRoundImageWithURLString(URLString: String?, cornerRadiusRatio: CGFloat? = nil, options: KingfisherManager.Options = KingfisherManager.DefaultOptions, progressBlock: ImageDownloaderProgressBlock? = nil)  { ... }

// version 2.4.1
func kfe_setRoundImageWithURLString(URLString: String?, cornerRadiusRatio: CGFloat? = nil, options: KingfisherOptionsInfo? = nil, progressBlock: ImageDownloaderProgressBlock? = nil) { ... }

// version 1.8.5
func kfe_setImageWithURLString(URLString: String?,
        placeholderImage: UIImage?,
        optionsInfo: KingfisherOptionsInfo?,
        progressBlock: DownloadProgressBlock?,
        completionHandler: CompletionHandler?) -> RetrieveImageTask?
    {
            ...
            let defaultOptions: KingfisherOptionsInfo = [
                .Options([.BackgroundDecode, .LowPriority]),
                .Transition(ImageTransition.Fade(0.55))
            ]
           ...
    }

// version 2.4.1
func kfe_setImageWithURLString(URLString: String?,
                                   placeholderImage: UIImage?,
                                   optionsInfo: KingfisherOptionsInfo?,
                                   progressBlock: DownloadProgressBlock?,
                                   completionHandler: CompletionHandler?) -> RetrieveImageTask?
    {
            ...       
            let defaultOptions: KingfisherOptionsInfo = [
                .BackgroundDecode,
                .DownloadPriority(NSURLSessionTaskPriorityLow),
                .Transition(ImageTransition.Fade(0.55))
            ]
            ...
    }

@alfredcc alfredcc reopened this May 26, 2016
@alfredcc
Copy link
Author

alfredcc commented May 26, 2016

@onevcat
Copy link
Owner

onevcat commented Aug 7, 2016

The cache system is always storing the original image now. There should be no chance in Kingfisher now to store a modified version of image. (It is a feature in plan and will be added later. Ref: #326 and #320)

@onevcat onevcat added the notsure label Aug 7, 2016
@alfredcc
Copy link
Author

alfredcc commented Aug 8, 2016

Thanks

@alfredcc alfredcc closed this as completed Aug 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants