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

UIImage extension scaling change scale property of image to uiscreen default #277

Closed
neokree opened this issue Aug 9, 2017 · 2 comments
Closed
Assignees
Milestone

Comments

@neokree
Copy link

neokree commented Aug 9, 2017

Hello,
I have an image loaded from assets. This image have a image.scale property equal to 1.0.
Now after I use .af_imageScaled or .af_imageAspectScaled on that I see that property will change to 2.0, which I think is the same as issue #89.

I tried to inspect your code, and I found that you call in either extensions this method:
UIGraphicsBeginImageContextWithOptions(size, af_isOpaque, 0.0) where the third parameter is the scale and if is setted to 0.0 the device main screen scale is used (from Apple documentation here: https://developer.apple.com/documentation/uikit/1623912-uigraphicsbeginimagecontextwitho?language=objc).

There would be useful if you let the developer set the UIImage scale value.
In my case, I don't need to use the image in a view but I'm scaling it for sending a thumbnail to a server and this method is doubling the image size only because my device screen have a scale of 2.0.

Please let me know if you would add a scale parameter on af_* extensions.
Thank you for your library and your time

DevTchernov pushed a commit to icerockdev/AlamofireImage that referenced this issue Aug 21, 2017
DevTchernov pushed a commit to icerockdev/AlamofireImage that referenced this issue Aug 21, 2017
DevTchernov pushed a commit to icerockdev/AlamofireImage that referenced this issue Aug 21, 2017
DevTchernov pushed a commit to icerockdev/AlamofireImage that referenced this issue Aug 21, 2017
@cnoon cnoon self-assigned this Feb 22, 2020
@cnoon
Copy link
Member

cnoon commented Feb 22, 2020

Hi @neokree, thank you for filing this issue. I've just pushed change 61a029d into master which will go out shortly in AFI 4.0.0. It changes all the UIImage extensions to expose a scale parameter which defaults to nil allowing you to override the scale value used in UIGraphicsBeginImageContextWithOptions API. I've also changed the default behavior to no longer use a default of 0.0, but instead the scale of the image. This should result in much more consistent and expected behavior across the board. It was never really correct to have these functions setting the scale value to UIScreen.main.scale.

As a secondary addition, I've added the ability to customize the ImageResponseSerializer per download through the ImageDownloader and extension APIs on UIImageView and UIButton. This allows you to change the scale factor of the image download through both APIs which could only be done previously if you used the Alamofire.Session directly which no one wants to actually do. This should make the APIs much more flexible to do what you want in all situations regardless of whether you're using an Alamofire.Session, AlamofireImage.ImageDownloader, or UIImageView or UIButton extension.

This change will be released as part of AFI 4.0.0 here shortly.

Cheers. 🍻

@cnoon cnoon closed this as completed Feb 22, 2020
@cnoon cnoon added this to the 4.0.0 milestone Feb 22, 2020
@neokree
Copy link
Author

neokree commented Feb 24, 2020

Hi @cnoon , thank you for your work!
I will wait for the 4.0.0 then

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

No branches or pull requests

3 participants
@cnoon @neokree and others