-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Allow exclusive use of .cacheOriginalImage file instead of final file #810
Comments
Hi, @ethansinjin Thanks for reporting this! Yes, this is a problem. For now, as a quick workaround, you need to also implement your own Like this: public struct MyCacheSerializer: CacheSerializer {
public func data(with image: Image, original: Data?) -> Data? {
return DefaultCacheSerializer.default.data(with: image, original: original)
}
public func image(with data: Data, options: KingfisherOptionsInfo?) -> Image? {
let image = DefaultCacheSerializer.default.image(with: data, options: options)
return image?.withRenderingMode(.alwaysOriginal)
}
} And also set it as an option. Re-running of the processor on a processed image might cause some confusion, so compared to re-running, I personally prefer to adding an option to not cache the final image in your suggestion. However, what I am concerning is that, is this a good use case for an image processor/serializer or not? An In your case, instead of manipulating the data, you are in fact setting some properties for the image. It should happen just before you set the image to the view. So maybe a better way is injecting the setting image by adding something like "imageModifier" to give the user a final chance to modify the images already in memory, just before send it to an image view or a button. How do you think about it? |
Thanks for the quick response and the workaround! I like the idea of an Please let me know if you plan to start a PR; I'd be happy to start one if needed! |
Great. Sure, I'd like to receive one from you, if you wish to add it. : ] |
And you could check the existing |
Check List
Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.
Issue Description
UIButtons of type .system use a property called
imageRenderingMode
of their image to determine if the image should be used in template or original mode.I have created a custom ImageProcessor,
RenderingModeImageProcessor
, to set the rendering mode of an image.I am trying use Kingfisher with a UIButton as follows:
What
The first time the image is downloaded, everything works perfectly. My image is rounded and the rendering mode is set to .alwaysOriginal by my custom image processor.
When the image is taken from the cache, the processors are not rerun, even though the original image is cached, because the "final image" is also cached.
Reproduce
Create a RenderingModeImageProcessor, such as the one in the code block below (my code, MIT License):
Use the ImageProcessor above with an image on a UIButton.
Other Comment
When using the option .forceRefresh, the processor gets a chance to run every time. This is a bad workaround though because it completely avoids caching.
Suggested Fix
Add an option to avoid using the final image, or to just not cache the final image
OR
Add an option to run processors even when the image is cached.
OR
A combination of both of the above.
If this problem is recognized, I can work on a PR if necessary.
The text was updated successfully, but these errors were encountered: