From b7b14ca8d4cdc52a6349f4c1bd15a24c9c032588 Mon Sep 17 00:00:00 2001 From: Danny Morrow Date: Sat, 12 Jan 2013 09:33:07 -0500 Subject: [PATCH] Fix for issue #9 - Broken on images taken by device's camera in portrait https://github.com/mattgemmell/MGImageUtilities/issues/9 Takes into account that rotated images don't have their CGImage rotated, so the rect needs to be rotated to crop correctly. --- .DS_Store | Bin 0 -> 6148 bytes Classes/UIImage+ProportionalFill.h | 3 +++ Classes/UIImage+ProportionalFill.m | 6 ++++++ 3 files changed, 9 insertions(+) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..05bc98dab43c1cfe921d6471e8f321d8751885ec GIT binary patch literal 6148 zcmeHKOG*Pl5Pcm-68u2WjkubXOCdKH;)u9#72GQ`5|s=SOoA@Q0|*|)i@5Ltp1?!+ zs=E!-PO`~DBvgf}*Pp8H>Ic)624MQLya#jvbf|*S7R>^YdC`Wn{KyW`$Qq+zZ;+M6 zxZ$Y-%78NP9~qEuH^MQ7xWhE~ep`>v^|_)<(|k6~fcL$ZFME`ETv6sr=f=0SJE8q5 zfo+^%glkOryTK&b6-S>@R zsLYJKJRw7goV_s~*t!q0HJcyIW~Fr&oN2{%=G_0Be5G{)eoSmhR46R@mM*uR|k!K0uUn(TVcB^4Pxvu@mM+J48^!mq6;= __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.