-
-
Notifications
You must be signed in to change notification settings - Fork 556
Description
We are sometimes noticing when images are scaled using .thumbnailKey they appear blurry. I wonder if its cause in func makeThumbnail(data: Data, options: ImageRequest.ThumbnailOptions) -> PlatformImage?
scale is not taken into account when returning back the UIImage. Which is causing the dimensions of the image to be reported incorrectly.
We do some post processing via prepareThumbnail
if the returned thumbnail size does not match the view size exactly and the scaled down image returned using https://developer.apple.com/documentation/uikit/uiimage/3750845-preparethumbnailofsize is too blurry.
Heres a sample request and response to show the issue
▿ ImageRequest(resource: "some url (hidden for privacy)", priority: normal, processors: [], options: Options(rawValue: 0), userInfo: [Nuke.ImageRequest.UserInfoKey(rawValue: "github.com/kean/nuke/thumbnail"): Nuke.ImageRequest.ThumbnailOptions(targetSize: Nuke.ImageRequest.ThumbnailOptions.TargetSize.fixed(474.0), createThumbnailFromImageIfAbsent: true, createThumbnailFromImageAlways: true, createThumbnailWithTransform: true, shouldCacheImmediately: true), Nuke.ImageRequest.UserInfoKey(rawValue: "imageSize"): (110.0, 158.0)])
▿ ref : <Container: 0x600001819c40>
(lldb) po response.image
<UIImage:0x6000030307e0 anonymous {338, 474} renderingMode=automatic(original)>
(lldb) po response.image.size
▿ (338.0, 474.0)
- width : 338.0
- height : 474.0
As you can see image size is reported in pixel size and not points. The fix might be that when we return PlatformImage in Nuke.makeThumbnail use scale initializer for UIImage.
Nuke/Sources/Nuke/Internal/Graphics.swift
Line 369 in 084076d
return PlatformImage(cgImage: image) |
return PlatformImage(cgImage: image, scale: scale, orientaion: orientation)
instead of return PlatformImage(cgImage: image)
I had to do that in an app i was working on as well