Skip to content

Commit

Permalink
Fix for issue mattgemmell#9 - Broken on images taken by device's came…
Browse files Browse the repository at this point in the history
…ra in portrait

mattgemmell#9

Takes into account that rotated images don't have their CGImage rotated, so the rect needs to be rotated to crop correctly.
  • Loading branch information
dmorrow committed Jan 12, 2013
1 parent 7b930fb commit b7b14ca
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions Classes/UIImage+ProportionalFill.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ typedef enum {
- (UIImage *)imageCroppedToFitSize:(CGSize)size; // uses MGImageResizeCrop
- (UIImage *)imageScaledToFitSize:(CGSize)size; // uses MGImageResizeScale


- (CGAffineTransform)transformForOrientation:(CGSize)newSize ;

@end
6 changes: 6 additions & 0 deletions Classes/UIImage+ProportionalFill.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ - (UIImage *)imageToFitSize:(CGSize)fitSize method:(MGImageResizingMethod)resize

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
CGImageRef sourceImg = nil;

if (self.imageOrientation == UIImageOrientationRight || self.imageOrientation == UIImageOrientationLeft)
{
sourceRect = CGRectMake(sourceRect.origin.y, sourceRect.origin.x, sourceRect.size.height, sourceRect.size.width);
}

if ([UIScreen instancesRespondToSelector:@selector(scale)]) {
UIGraphicsBeginImageContextWithOptions(destRect.size, NO, 0.f); // 0.f for scale means "scale for device's main screen".
sourceImg = CGImageCreateWithImageInRect([self CGImage], sourceRect); // cropping happens here.
Expand Down

1 comment on commit b7b14ca

@TonSilver
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extremely important patch! Thanx =)

Please sign in to comment.