Skip to content

Commit 75a7581

Browse files
kiyun-gthomasvl
authored andcommitted
Fix gtm_imageByRotating (#541)
Fix the new implementation that was added in c5ac5c2. Update the unit tests to at least check the output dimensions. The updated unit tests fail before this change and succeed with the change.
1 parent 8a801ab commit 75a7581

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

iPhone/GTMUIImage+Resize.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ - (UIImage *)gtm_imageByRotating:(UIImageOrientation)orientation {
159159

160160
UIGraphicsImageRendererFormat *rendererFormat = [[UIGraphicsImageRendererFormat alloc] init];
161161
rendererFormat.scale = self.scale;
162-
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:self.size
162+
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:bounds.size
163163
format:rendererFormat];
164164
UIImage *rotatedImage =
165165
[renderer imageWithActions:^(UIGraphicsImageRendererContext *_Nonnull rendererContext) {

iPhone/GTMUIImage+ResizeTest.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,21 +239,36 @@ - (void)testImageByRotating {
239239
UIImage *landscapeImage = [self testImageNamed:@"GTMUIImage+Resize_100x50"];
240240
XCTAssertNotNil(landscapeImage, @"Unable to read image.");
241241

242+
CGSize size50x100 = CGSizeMake(50, 100);
243+
CGSize size100x50 = CGSizeMake(100, 50);
244+
242245
// Rotate 90 degrees.
243246
UIImage *actual = [landscapeImage gtm_imageByRotating:UIImageOrientationRight];
244247
XCTAssertNotNil(actual);
248+
XCTAssertTrue(CGSizeEqualToSize([actual size], size50x100),
249+
@"Resized image should equal size: %@ actual: %@", NSStringFromCGSize(size50x100),
250+
NSStringFromCGSize([actual size]));
245251

246252
// Rotate 180 degrees.
247253
actual = [landscapeImage gtm_imageByRotating:UIImageOrientationDown];
248254
XCTAssertNotNil(actual);
255+
XCTAssertTrue(CGSizeEqualToSize([actual size], size100x50),
256+
@"Resized image should equal size: %@ actual: %@", NSStringFromCGSize(size100x50),
257+
NSStringFromCGSize([actual size]));
249258

250259
// Rotate 270 degrees.
251260
actual = [landscapeImage gtm_imageByRotating:UIImageOrientationLeft];
252261
XCTAssertNotNil(actual);
262+
XCTAssertTrue(CGSizeEqualToSize([actual size], size50x100),
263+
@"Resized image should equal size: %@ actual: %@", NSStringFromCGSize(size50x100),
264+
NSStringFromCGSize([actual size]));
253265

254266
// Rotate 360 degrees.
255267
actual = [landscapeImage gtm_imageByRotating:UIImageOrientationUp];
256268
XCTAssertNotNil(actual);
269+
XCTAssertTrue(CGSizeEqualToSize([actual size], size100x50),
270+
@"Resized image should equal size: %@ actual: %@", NSStringFromCGSize(size100x50),
271+
NSStringFromCGSize([actual size]));
257272
}
258273

259274
@end

0 commit comments

Comments
 (0)