Skip to content

Instantly share code, notes, and snippets.

@cruffenach
Created May 16, 2013 18:24
Show Gist options
  • Save cruffenach/5593888 to your computer and use it in GitHub Desktop.
Save cruffenach/5593888 to your computer and use it in GitHub Desktop.
- (UIImage *)imageScaledToSizeKeepingAspectRatioWithWidth:(CGFloat)targetMinimumWidth contextSize:(CGSize)contextSize {
CGSize originalSize = self.size;
CGFloat newHeight = (originalSize.height / originalSize.width) * targetMinimumWidth;
UIGraphicsBeginImageContextWithOptions(contextSize, NO, 1);
[self drawInRect:CGRectMake(0, 0, targetMinimumWidth, newHeight)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment