Swiftpack.co - Package - imgix/imgix-swift

imgix logo

imgix-swift is a client library for generating image URLs with imgix. Written in Swift, but can be used with Objective-C codebases as well.

CocoaPods Carthage compatible Build Status Supported Platforms License


Installation

// add the following to your Package.swift manifest, within the dependencies array

.package(url: "https://github.com/imgix/imgix-swift.git", from: "1.0.0")

// add the package name "ImgixSwift" to the list of named dependencies in your project target

.target(
    name: "YourSwiftProject",
    dependencies: ["ImgixSwift"]),

As of version 1.0.0 imgix Swift client is compatible with Swift 5.0.

The latest version compatible with Swift 4.0 is 0.4.3.

The latest version compatible with Swift 3.0 is 0.3.0.

Usage

Swift

// 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.

Github

link
Stars: 19

Dependencies

Used By

Total: 0

Releases

1.1.0 - 2020-02-12 22:32:16

  • build(spm): add swift package manifest (#21)
  • refactor: use Swift CommonCrypto module to calculate md5 hashes (#22)

1.0.0 - 2020-01-31 21:24:57

  • build: update to support Swift 5 (#17)

0.4.3 - 2018-09-27 23:59:00

-Sort URL query parameters when building a URL. -Add documentation on Swift version.

0.4.2 - 2018-08-30 23:14:31

  • Improves performance while encoding URI items

0.4.1 - 2018-08-16 23:02:17

  • Fixed warnings for app extensions.

0.4.0 - 2018-06-29 23:54:07

  • Support Swift 4.

0.3.0 - 2016-11-04 19:35:28

  • Added ImgixClient#reconstruct method. Usage is outlined in the documentation: https://github.com/imgix/imgix-swift#url-reconstruction

0.2.0 - 2016-10-01 00:03:42

Swift 3 support!

0.1.4 - 2016-09-01 22:11:38

  • Relax minimum deployment targets for iOS and macOS to 9.0 and 10.10, respectively.

0.1.3 - 2016-09-01 00:19:20

  • Fixes an issue when using certain params with secure sources. See #3 for details.

0.1.2 - 2016-07-06 07:44:42

  • Update podspec to generate proper SWIFT_OBJC_INTERFACE_HEADER_NAME.

0.1.1 - 2016-07-06 07:05:24

0.1.0 - 2016-07-06 06:34:02

  • Initial release!