Latest 0.4.3
Homepage https://github.com/imgix/imgix-swift
License BSD 2-Clause
Platforms ios 9.0, osx 10.10, tvos 9.2, requires ARC
Authors

imgix logo

imgix-swift Build Status Carthage compatible CocoaPods

The official imgix Swift client. Written in Swift, but plays nice with Objective-C codebases, too! 👌

imgix is a real-time image processing service and CDN. It lets you edit images on the fly by changing their URL query string parameters. That means you can crop and resize images without having to batch process them or store derivative versions. You can also automatically detect faces, overlay text and other images, and perform advanced compositing operations. To learn more about what you can do with imgix, check out our site and documentation.

Installation

Usage

Swift

The imgix Swift client is compatible with Swift 4.0.

The lastest version compatible with Swift 3.0 is 0.3.0.

// Import the framework
import ImgixSwift

// Set up an ImgixClient
let client = ImgixClient.init(host: "assets.imgix.net")

// Build a basic URL
client.buildUrl("dog.jpg") // => https://assets.imgix.net/dog.jpg

// Add some parameters
client.buildUrl("dog.jpg", params: [
  "w": 300,
  "h": 300,
  "fit": "crop"
]) // => https://assets.imgix.net/dog.jpg?fit=crop&h=300&w=300

Objective-C

If your project doesn’t contain any other Swift code, make sure to set your target’s Build Settings > Build Options > Embedded Content Contains Swift Code to YES.

// Import the framework
#import <ImgixSwift/ImgixSwift.h>

// Set up an ImgixClient
ImgixClient *client = [[ImgixClient alloc] initWithHost:@"assets.imgix.net"];

// Build a basic URL
[client buildUrl:@"dog.jpg"]; // => https://assets.imgix.net/dog.jpg

// Add some parameters
[client buildUrl:@"dog.jpg", params:@{
  @"w": @300,
  @"h": @300,
  @"fit": @"crop",
}]; // => https://assets.imgix.net/dog.jpg?fit=crop&h=300&w=300

Advanced Usage

Automatic Signing

If you’re using a source that requires signed URLs, imgix-swift can automatically build and sign them for you.

let signedClient = ImgixClient.init(
  host: "imgix-library-secure-test-source.imgix.net",
  secureUrlToken: "EHFQXiZhxP4wA2c4"
)

signedClient.buildUrl("dog.jpg", params: [
  "bri": 50
]) // => https://imgix-library-secure-test-source.imgix.net/dog.jpg?bri=50&s=3b293930d9c288fb788657fd9ed8164f

Automatic Base64 Encoding

imgix-swift will automatically Base64-encode any parameter key ending in 64, according to the requirements of imgix’s Base64 variant parameters.

let client = ImgixClient.init(host: "assets.imgix.net")

client.buildUrl("dog.jpg", params: [
  "w": 640,
  "txt64": "🐶 Puppy!",
  "txtfont64": "Avenir Next Demi,Bold",
  "txtalign": "center,top",
  "txtpad": 50,
  "txtshad": 10,
  "txtclr": "fff",
  "txtfit": "max",
  "txtsize": 50
]) // => https://assets.imgix.net/dog.jpg?txt64=8J-QtiBQdXBweSE&txtalign=center%2Ctop&txtclr=fff&txtfit=max&txtfont64=QXZlbmlyIE5leHQgRGVtaSxCb2xk&txtpad=50&txtshad=10&txtsize=50&w=640

URL Reconstruction

You can reconstruct existing URLs by using the ImgixClient#reconstruct method. Existing parameters on the input URL will be merged and/or overridden by passed params.

let client = ImgixClient.init(host: "assets.imgix.net")
let inputUrl = URL.init(string: "https://paulstraw.imgix.net/pika.jpg?w=300")!

client.reconstruct(originalURL: inputUrl, params: [
  "h": 300,
  "fit": "crop"
]) // => https://paulstraw.imgix.net/pika.jpg?fit=crop&h=300&w=300

What is the ixlib param?

For security and diagnostic purposes, we default to signing all requests with the language and version of library used to generate the URL. This can be disabled by setting client.includeLibraryParam = false.

Latest podspec

{
    "name": "ImgixSwift",
    "version": "0.4.3",
    "summary": "The official imgix Swift client. Written in Swift, but plays nice with Objective-C codebases, too! ud83dudc4c",
    "license": {
        "type": "BSD 2-Clause",
        "file": "LICENSE.md"
    },
    "homepage": "https://github.com/imgix/imgix-swift",
    "authors": {
        "Paul Straw": "[email protected]"
    },
    "source": {
        "git": "https://github.com/imgix/imgix-swift.git",
        "tag": "0.4.3"
    },
    "xcconfig": {
        "SWIFT_OBJC_INTERFACE_HEADER_NAME": "ImgixSwift.h"
    },
    "requires_arc": true,
    "source_files": [
        "Sources/*.{h,m,swift}"
    ],
    "platforms": {
        "ios": "9.0",
        "osx": "10.10",
        "tvos": "9.2"
    }
}

Pin It on Pinterest

Share This