#define radians(degrees) (degrees * M_PI/180)
UIImage *rotate(UIImage *image) {
CGSize size = image.size;;
UIGraphicsBeginImageContext(size);
CGContextRef co
I liked the solution by @lbsweek but I was bit worried about alloc ing UIView just for transform, instead I tried the below
- (UIImage *)rotateImage:(UIImage *)sourceImage byDegrees:(float)degrees
{
CGFloat radian = degrees * (M_PI/ 180);
CGRect contextRect = CGRectMake(0, 0, sourceImage.size.width, sourceImage.size.height);
float newSide = MAX([sourceImage size].width, [sourceImage size].height);
CGSize newSize = CGSizeMake(newSide, newSide);
UIGraphicsBeginImageContext(newSize);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGPoint contextCenter = CGPointMake(CGRectGetMidX(contextRect), CGRectGetMidY(contextRect));
CGContextTranslateCTM(ctx, contextCenter.x, contextCenter.y);
CGContextRotateCTM(ctx, radian);
CGContextTranslateCTM(ctx, -contextCenter.x, -contextCenter.y);
[sourceImage drawInRect:contextRect];
UIImage* rotatedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return rotatedImage;
}