---
title: "#40: Toucan 🐧"
url: https://littlebitesofcocoa.com/40-toucan
author: Jake Marsh
published: 2015-07-17
topics: ["Libraries","Images"]
description: "Whether you're applying a circular crop to user avatars or just resizing a photo downloaded from a web service, processing images can be a bit of a chore."
---

# #40: Toucan 🐧

By Jake Marsh, July 17, 2015. HTML: https://littlebitesofcocoa.com/40-toucan

Whether you're applying a circular crop to user avatars or just resizing a photo downloaded from a web service, processing images can be a bit of a chore. **Toucan** is a **Swift** image processing library from [Gavin Bunney](https://github.com/gavinbunney) that makes working with images a breeze.

Let's `import Toucan` and take a look at what it can do:

## Resize Images

<img src="https://media.littlebitesofcocoa.com/bite-assets/040-toucan-resize.png" style="max-width: 100px;" />

``` swift
// userAvatar is a UIImage downloaded from the network

let resizedAvatar = Toucan.Resize.resizeImage(
    myImage,
    size: CGSize(width: 100, height: 100)
)
```

## Apply a Circular Mask

<img src="https://media.littlebitesofcocoa.com/bite-assets/040-toucan-circular.png" style="max-width: 50px;" />

``` swift
let circularAvatar = Toucan.maskWithEllipse(resizedAvatar)
```

## Apply a Rounded Rectangle Mask

<img src="https://media.littlebitesofcocoa.com/bite-assets/040-toucan-rounded.png" style="max-width: 50px;" />

``` swift
let roundedAvatar = Toucan.maskWithRoundedRect(height: 5)
```

## Image Borders & Method Chaining

**Toucan** provides another syntax for chaining different processing steps together. Just call `.image` at the end to get a final processed `UIImage`. Here we can also see how to apply a 1 point wide border to the final image.

``` swift
Toucan(image: userAvatar)
  .resize(CGSize(width: 100, height: 100))
  .maskWithEllipse(
    borderWidth: 1, 
    borderColor: UIColor.lightGrayColor()
  )
  .image
```

More info about **Toucan** can be found at [git.io/toucan](http://git.io/toucan)
