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

Image not being properly rotated if ImageProcessor is applied #535

Closed
nbortolussi opened this issue Dec 8, 2016 · 7 comments
Closed

Image not being properly rotated if ImageProcessor is applied #535

nbortolussi opened this issue Dec 8, 2016 · 7 comments

Comments

@nbortolussi
Copy link

nbortolussi commented Dec 8, 2016

My image appears with the correct orientation with no processor applied. However, when a BlurProcessor is added to the image, the processor works correctly but the image is no longer rotated as it should be:

        backgroundImage.kf.setImage(with: image, placeholder: nil, options: [.processor(processor)])

@onevcat
Copy link
Owner

onevcat commented Dec 14, 2016

Umm..The BlurProcessor (as well as all of other processors) does not do anything on the orientation. Maybe you could implement a processor your own to normalize the image, if you need to display an image with different orientation settings. There is a kf.normalized property you could use for it.

The final processor might be something like this:

struct NormalizingProcessor: ImageProcessor {
    let identifier = "normalized"
    func process(item: ImageProcessItem, options: KingfisherOptionsInfo) -> Image? {
        switch item {
        case .image(let image):
            return image.kf.normalized
        case .data(_):
            return (DefaultImageProcessor() >> self).process(item: item, options: options)
        }
    }
}

let p = BlurImageProcessor(blurRadius: r) >> NormalizingProcessor()
imageView.kf.setImage(with: URL(string: ""), options: [.processor(p)])

@nbortolussi
Copy link
Author

If it is the case that the processors do not affect rotation at all then not sure why image.kf.setImage(with: image) and image.kf.setImage(with: image, placeholder: nil, options: [.processor(processor)]) gives different rotation results?

Anyway your recommendation with normalize did do the trick - thanks!

@onevcat
Copy link
Owner

onevcat commented Dec 20, 2016

It is due to the cgImage based filter. I will give it a better fix now.

@onevcat
Copy link
Owner

onevcat commented Dec 20, 2016

Fixed in 3.2.3.

@lastcc
Copy link

lastcc commented Aug 27, 2017

@onevcat Hi again.

I am using the latest version of KingFisher, and the image is not correctly displayed. Is there a way to fix this? Because the above post mentioned that this was fixed in 3.2.3.

The code snippet that I am using:

imageView.kf.setImage(with: asset.fileURL, placeholder: asset.transientImage, options: [.backgroundDecode])

After the transformation of an UIImage object to PNG Data object, the open var imageOrientation: UIImageOrientation information is lost forever.

So, set the image to UIImageView, the image is correctly displayed.

But after the data is persisted on disk and load again by KingFisher, the orientation is wrong.

See this, and this.

@onevcat
Copy link
Owner

onevcat commented Aug 27, 2017

@lastcc

As mentioned in your ref links, there is no exif information in a PNG file, so the rotation info in a JPEG will be lost in a PNG representation. I tried JPEG with non-unified orientation in latest Kingfisher and it works well in both loading from web or cache. (I was using this image: https://github.com/recurser/exif-orientation-examples/blob/master/Landscape_2.jpg for testing).

If you are loading a JPEG with problem, may I know the image url so I could have a deep look into it.

@lastcc
Copy link

lastcc commented Aug 28, 2017

@onevcat oh sorry I mean I have problems with PNGs. I think I may address my problem by passing an custom RotateProcessor to the method.

I was misunderstanding this GitHub issue, and thought it had something to do with processors. Since I also used blur. Turns out the problem is on my side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants