Add scale parameter to scale methods to allow setting the output image's scale. #360
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goals ⚽
At some point I needed a way of cropping an image and setting its size in pixels. I couldn't use af_imageAspectScaled for that because internally it would use the device's main screen scale factor. So, for example, if i scaled an image to the size CGSize(width: 320, height: 320), on an iPhone 6 the resulting image would have the dimensions 640x640 (in pixels) and in an iPhone 6+ the dimenstions would be 960x960.
My goal on this pull request is to allow explicitly setting the scale when scaling images.
Implementation Details 🚧
Modified the methods af_imageScaled(to size:), af_imageAspectScaled(toFill size:) and af_imageAspectScaled(toFit size:) to receive an additional parameter scale: CGFloat, which defaults to 0.0 (which is the defaul value set on UIGraphicsBeginImageContextWithOptions()).
Testing Details 🔍
I've added the test UIImageTestCase.testThatImageIsScaledWithProperScale.