Skip to content

Instantly share code, notes, and snippets.

@Arthraim
Last active August 29, 2015 14:10
Show Gist options
  • Save Arthraim/1dafdb1b9ff4cd81a32c to your computer and use it in GitHub Desktop.
Save Arthraim/1dafdb1b9ff4cd81a32c to your computer and use it in GitHub Desktop.
Resampling Image with GUIImage
+ (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