Skip to content

A set of handy categories for UIImage class. It allows filtering, resizing, masking, rotating.

License

Notifications You must be signed in to change notification settings

Critter/NYXImagesUtilities

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NYXImagesUtilities

This is a project for iOS which regroups a collection of useful UIImage categories to handle operations such as filtering, masking, rotating, resizing, saving. NYXImagesUtilities requires at least iOS 4.0, I don't intend to support older versions.

Installation

  • Link with QuartzCore framework.
  • Add #import <QuartzCore/QuartzCore.h> in your Prefix.pch file.
  • Add NYXImagesUtilities.h & NYXImagesUtilities.m and the categories you want to your project.

If want to use the saving category you must also link with :

  • ImageIO.framework
  • MobileCoreServices.framework

By default the methods return auto-released objects, if you want them to return retained objects in order to manage memory yourself, just uncomment the kNYXReturnRetainedObjects constant in NYXImagesUtilities.h.

UIImage+Filtering

This category allows you to apply filters on a UIImage object, currently there are 3 filters : Sepia, Grayscale and changing opacity.

Sepia image

Using these filters is very easy :

UIImage* sepia = [myImage sepia];
UIImage* gray = [myImage grayscale];
UIImage* transparent = [myImage opacity:0.5f];

UIImage+Masking

This category is composed of a single method which allow to mask an image, you just have to create the mask you desire.

UIImage* masked = [myImage maskWithImage:[UIImage imageNamed:@"mask.png"]];

UIImage+Resizing

This category can be used to crop or to scale images.

Cropping

You can crop your image by 9 different ways :

  1. Top left
  2. Top center
  3. Top right
  4. Bottom left
  5. Bottom center
  6. Bottom right
  7. Left center
  8. Right center
  9. Center

To crop an image object just call -(UIImage*)cropToSize:(CGSize)newSize usingMode:(NYXCropMode)cropMode; like this :

UIImage* cropped = [myImage cropToSize:(CGSize){width, height} usingMode:NYXCropModeCenter];

NYXCropMode is an enum type which can be found in the header file, it is used to represent the 9 modes above.

There is also a convenience method which crop from the top left corner by default : -(UIImage*)cropToSize:(CGSize)newSize;

Scaling

You have the choice between two methods to scale images, the two methods will keep the aspect ratio of the original image.

UIImage* scaled1 = [myImage scaleByFactor:0.5f];
UIImage* scaled2 = [myImage scaleToFitSize:(CGSize){width, height}];

UIImage+Rotating

With this category you can rotate or flip an UIImage object, flipping is useful if you want to create a reflect effect.

UIImage* rotated1 = [myImage rotateInDegrees:217.0f];
UIImage* rotated2 = [myImage rotateInRadians:M_PI_2];

UIImage* flipped1 = [myImage verticalFlip];
UIImage* flipped2 = [myImage forizontalFlip];

UIImage+Saving

This category allows you to save an UIImage object at a specified path or file URL, there are five types supported : BMP, GIF, JPG, PNG, TIFF.

To use it, you must link with ImageIO.framework and MobileCoreServices.framework.

[myImage saveToURL:url type:NYXImageTypeJPEG backgroundFillColor:nil];
[myImage saveToPath:path type:NYXImageTypeTIFF backgroundFillColor:[UIColor yellowColor]];

There is also two other methods which take only the path or URL as parameter and save the image in PNG, because it's the preferred format for iOS.

If your image contains transparent zone and you save it in a format that doesn't support alpha, a fill color will be used, if you don't specify one, the default color will be white.

License

NYXImageUtilities is released under the Simplified BSD license, see LICENSE.txt.

I hope you will find this useful, if you would like to see more features you can send me an email.

Benjamin Godard.

Blog : http://www.cocoabyss.com/

Twitter : @Nyx0uf

About

A set of handy categories for UIImage class. It allows filtering, resizing, masking, rotating.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published