Nuke icon indicating copy to clipboard operation
Nuke copied to clipboard

Disk image cache looses the information about image orientation

Open ekazaev opened this issue 3 years ago • 1 comments

Hi

I found a strange bug that I can not avoid.

I need both images for my task. The original one and a smaller preview. I find out that if I save that preview manually when it is being restored from the disk cache may loose its orientation.

A bit of background. If you rotate an image lets say 90 degree in the gallery app, the ios wont resample it, it will just add another orientation value to its metadata and present it according to its value.

If I download such image it has that metadata inside. ImageProcessors.Resize(width: 300).process(response.image) doesn't loose the orientation information either. So if I cache the preview image it is presented correctly up until I reboot the app. So it mean that the orientation is correctly saved in the memory cache, but it is being lost on the next start of the app when the preview image is restored from the image cache.

The example code that you can test is below:

            let resizingRequest = ImageRequest(url: imageURL, processors: [ImageProcessors.Resize(width: 300)], priority: .high)
            if let image = ImagePipeline.shared.cache.cachedImage(for: resizingRequest)?.image {
                self.image = image // After the restart the orientation
                print("\(image.imageOrientation.rawValue)")
            } else {
                ImagePipeline.shared.loadImage(with: imageURL, completion: { [weak self] result in
                    guard let self = self,
                          case let .success(response) = result,
                          let previewImage = ImageProcessors.Resize(width: 300).process(response.image),
                          let cgPreviewImage = previewImage.cgImage else {
                        return
                    }
                    print("\(previewImage.imageOrientation.rawValue)")
                    ImagePipeline.shared.cache.storeCachedImage(ImageContainer(image: previewImage), for: resizingRequest)
//                     ImagePipeline.shared.cache.storeCachedImage(ImageContainer(image: UIImage(cgImage: cgPreviewImage, scale: response.image.scale, orientation: response.image.imageOrientation)), for: resizingRequest)

                    self.image = image
                })
            }

ekazaev avatar Jul 28 '22 17:07 ekazaev

Hi, have you found a solution? Can you please provide an image URL with which you can reproduce it?

kean avatar Aug 20 '22 14:08 kean

Fixed in Nuke 11.6.0 (update: pulled from GitHub temporarily)

kean avatar Dec 27 '22 03:12 kean

I also have the same problem. @kean Where can I find 11.6.0 version?

Madrox24 avatar Jan 04 '23 13:01 Madrox24

@Madrox24, version 11.6.0 is now available

kean avatar Feb 02 '23 04:02 kean