Toucan is a Swift library that provides a clean, quick API for processing images. It greatly simplifies the production of images, supporting resizing, cropping and stylizing your images.
Features
Easy and smart resizing
Elliptical and rounded rect masking
Mask with custom images
Chainable image processing stages
Planned for 1.0 Release
100% Unit Test Coverage - once image loading in XCTests are fixed!
Add crop options for crop location & faces
Add enhancement filters to beautify images
Add stylize filters
Add rotation and flip support
Lazy evaluation of image contexts to prevent having to create and close multiple contexts during method chaining
Requirements
Xcode 6
iOS 7.0+
Setup
Include the Toucan framework by dragging it into your project and import the library in your code using import Toucan
Currently there are issues loading the library using pod 'Toucan' which is pending changes from Cocoapods.
Toucan Usage
Toucan provides two methods of interaction - either through wrapping an single image within a Toucan instance, or through the static functions, providing an image for each invocation. This allows for some very flexible usage.
Create an instance wrapper for easy method chaining:
let resizedAndMaskedImage =Toucan(image: myImage).resize(CGSize(width: 100, height: 150)).maskWithEllipse().image
Or, using static methods when you need a single operation:
let resizedImage = Toucan.Resize.resizeImage(myImage, size: CGSize(width: 100, height: 150))
let resizedAndMaskedImage = Toucan.maskWithEllipse(resizedImage)
Resizing
Resize the contained image to the specified size. Depending on what fitMode is supplied, the image may be clipped, cropped or scaled.
Alter the original image with a mask; supports ellipse, rounded rect and image masks.
Ellipse Mask
Example
Function
Mask the given image with an ellipse. Allows specifying an additional border to draw on the clipped image. For a circle, ensure the image width and height are equal!
Toucan(image: myImage).maskWithEllipse().image or Toucan.Mask.maskImageWithEllipse(myImage) -> UIImage
When specifying a border width, it is draw on the clipped image.
Mask the given image with another image mask. Note that the areas in the original image that correspond to the black areas of the mask show through in the resulting image. The areas that correspond to the white areas of the mask aren’t painted. The areas that correspond to the gray areas in the mask are painted using an intermediate alpha value that’s equal to 1 minus the image mask sample value.
Toucan(image: myImage).maskWithImage(maskImage: octagonMask).image or Toucan.Mask.maskImageWithImage(myImage, maskImage: octagonMask) -> UIImage
Example Images
Example images used under Creative Commons with thanks to: