summaryrefslogtreecommitdiff
path: root/Juick/Helpers/UIImage+Utils.m
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-08-28 21:03:22 +0300
committerGravatar Vitaly Takmazov2016-08-28 21:03:22 +0300
commit188d8e4ea870d1a6c8edd5a9b323742804badeba (patch)
tree071067f7189a6474d49abb952b1b04b820985b7a /Juick/Helpers/UIImage+Utils.m
parenta74588083c4950e9237dff7a84ccdd129b72c950 (diff)
project cleanup
Diffstat (limited to 'Juick/Helpers/UIImage+Utils.m')
-rw-r--r--Juick/Helpers/UIImage+Utils.m69
1 files changed, 69 insertions, 0 deletions
diff --git a/Juick/Helpers/UIImage+Utils.m b/Juick/Helpers/UIImage+Utils.m
new file mode 100644
index 0000000..4617c65
--- /dev/null
+++ b/Juick/Helpers/UIImage+Utils.m
@@ -0,0 +1,69 @@
+//
+// UIImage+Utils.m
+// Juick
+//
+// Created by Vitaly on 01.02.14.
+// Copyright (c) 2014 com.juick. All rights reserved.
+//
+
+#import "UIImage+Utils.h"
+
+@implementation UIImage (Utils)
+
++ (UIImage*)imageWithImage:(UIImage *)image convertToWidth:(float)width covertToHeight:(float)height {
+ CGSize size = CGSizeMake(width, height);
+ UIGraphicsBeginImageContext(size);
+ [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
+ UIImage * newimage = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
+ return newimage;
+}
+
++ (UIImage*)imageWithImage:(UIImage *)image convertToHeight:(float)height {
+ float ratio = image.size.height / height;
+ float width = image.size.width / ratio;
+ CGSize size = CGSizeMake(width, height);
+ UIGraphicsBeginImageContext(size);
+ [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
+ UIImage * newimage = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
+ return newimage;
+}
+
++ (UIImage*)imageWithImage:(UIImage *)image convertToWidth:(float)width {
+ float ratio = image.size.width / width;
+ float height = image.size.height / ratio;
+ CGSize size = CGSizeMake(width, height);
+ UIGraphicsBeginImageContext(size);
+ [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
+ UIImage * newimage = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
+ return newimage;
+}
+
++ (UIImage*)imageWithImage:(UIImage *)image fitInsideWidth:(float)width fitInsideHeight:(float)height {
+ if (image.size.height >= image.size.width) {
+ return [UIImage imageWithImage:image convertToWidth:width];
+ } else {
+ return [UIImage imageWithImage:image convertToHeight:height];
+ }
+}
+
++ (UIImage*)imageWithImage:(UIImage *)image fitOutsideWidth:(float)width fitOutsideHeight:(float)height {
+ if (image.size.height >= image.size.width) {
+ return [UIImage imageWithImage:image convertToHeight:height];
+ } else {
+ return [UIImage imageWithImage:image convertToWidth:width];
+ }
+}
+
++ (UIImage*)imageWithImage:(UIImage *)image cropToWidth:(float)width cropToHeight:(float)height {
+ CGSize size = [image size];
+ CGRect rect = CGRectMake(((size.width-width) / 2.0f), ((size.height-height) / 2.0f), width, height);
+ CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect);
+ UIImage * img = [UIImage imageWithCGImage:imageRef];
+ CGImageRelease(imageRef);
+ return img;
+}
+
+@end