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 7.2
- iOS 8.0+
As of version 0.4, Toucan only supports Swift 2. Use version 0.3.x for the latest Swift 1.2 compatible release
Setup
- Install using Cocoapods: https://cocoapods.org/pods/Toucan
- or manually include the
Toucan
framework by dragging it into your project and import the library in your code usingimport Toucan
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)
Typically, the instance version is a bit cleaner to use, and the one you want.
Resizing
Resize the contained image to the specified size. Depending on what fitMode
is supplied, the image may be clipped, cropped or scaled.
Toucan(image: myImage).resize(size: CGSize, fitMode: Toucan.Resize.FitMode)
Fit Mode
FitMode drives the resizing process to determine what to do with an image to make it fit the given size bounds.
Masking
Alter the original image with a mask; supports ellipse, rounded rect and image masks.
Ellipse Mask
Path Mask
Rounded Rect Mask
Image Mask
Example Images
Example images used under Creative Commons with thanks to:
Contributing
- Please fork this project
- Implement new methods or changes in the
Toucan.swift
file. - Write tests in the
ToucanTests
folder. - Write appropriate docs and comments in the README.md
- Submit a pull request.
Contact
Raise an Issue or hit me up on Twitter @gavinbunney
License
Toucan is released under an MIT license. See LICENSE for more information.