/iris

A Swift framework for working with Imgix.

Primary LanguageSwiftMIT LicenseMIT

Iris

Build Status Carthage Compatible CocoaPods Compatible

A Swift framework for working with Imgix.

Requirements

Xcode Swift iOS tvOS macOS
9.0 4.0 8.0 9.0 10.10

Installation

github "hodinkee/Iris" ~> 3.0
pod "Iris", "~> 3.0"

Usage

Let's say you have an Imgix Web Folder or Amazon S3 source setup. You then have a plain URL to an image resource like the one below.

let imageURL = NSURL(string: "https://my-source.imgix.net/path/to/my/image")

Now, the original image is a rather large 1920x1080px photo of Yosemite, but your app displays it in a 320x180pt view. It would be incredibly wasteful of bandwidth and memory to download the original image. Let's fix that by asking Imgix to resize it for us.

let displayScale = imageView.traitCollection.displayScale
let imageOptions = ImageOptions(width: 320, height: 180, scale: displayScale)
let resizedImageURL = imageURL?.imgixURL(imageOptions: imageOptions)

Want to ensure the resized image is in the JPEG file format with a quality of 50? Just configure the options!

imageOptions.format = .JPEG
imageOptions.quality = 50

If you need to sign your Imgix URLs, whether just for security's sake or because you're using a Web Proxy Source, there's a way to do that too!

let signingOptions = SigningOptions(host: "my-source.imgix.net", token: "FOObar123")
let signedImageURL = imageURL?.imgixURL(imageOptions: imageOptions, signingOptions: signingOptions)