Last active
August 29, 2015 14:10
-
-
Save Arthraim/1dafdb1b9ff4cd81a32c to your computer and use it in GitHub Desktop.
Resampling Image with GUIImage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (UIImage *)compressForUpload:(UIImage *)original | |
{ | |
// Calculate new size given scale factor. | |
CGSize originalSize = original.size; | |
CGFloat longerBorder = MAX(originalSize.width, originalSize.height); | |
CGFloat scale = longerBorder > MAX_DISTANCE_OF_LONGER_EDGE ? longerBorder / MAX_DISTANCE_OF_LONGER_EDGE : 1; | |
CGSize newSize = CGSizeMake(originalSize.width / scale, originalSize.height / scale); | |
GPUImageLanczosResamplingFilter *resampleFilter = [[GPUImageLanczosResamplingFilter alloc] init]; | |
[resampleFilter forceProcessingAtSize:newSize]; | |
return [resampleFilter imageByFilteringImage:original]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment