• Stars
    star
    25
  • Rank 957,573 (Top 19 %)
  • Language
    Swift
  • License
    BSD 2-Clause "Sim...
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Swift client library for generating URLs with imgix

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 FOSSA Status


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.

License

FOSSA Status

More Repositories

1

drift

Easily add "zoom on hover" functionality to your site's images. Lightweight, no-dependency JavaScript.
JavaScript
1,527
star
2

imgix.js

Responsive images in the browser, simplified
JavaScript
965
star
3

luminous

A simple, lightweight, no-dependencies JavaScript lightbox
JavaScript
771
star
4

react-imgix

React component to display imgix images
JavaScript
360
star
5

prometheus-am-executor

Execute command based on Prometheus alerts
Go
234
star
6

js-core

A JavaScript client library for generating image URLs with imgix
JavaScript
122
star
7

imgix-php

A PHP client library for generating URLs with imgix
PHP
111
star
8

imgix-rails

A gem for integrating imgix into Rails projects
Ruby
110
star
9

imgix-rb

A Ruby gem for generating image URLs with imgix
Ruby
76
star
10

jekyll-imgix

A plugin for integrating imgix into Jekyll sites
Ruby
51
star
11

motif

A simple Rails app to create responsive social images
HTML
41
star
12

imgix-url-params

Organized, machine-friendly documentation of imgix's URL parameters
39
star
13

imgix-python

A Python client library for generating URLs with imgix
Python
37
star
14

vue

A simple yet powerful integration between Vue and imgix
TypeScript
35
star
15

gatsby

A simple yet powerful integration between Gatsby and imgix
TypeScript
30
star
16

imgix-objc

Official imgix Objective-C client.
Objective-C
29
star
17

ember-cli-imgix

Easily add imgix functionality to your Ember application
JavaScript
26
star
18

magento

Browse, search, and insert image assets into your storefront quickly and easily via the imgix Image Manager.
JavaScript
21
star
19

imgix-emacs

An emacs major-mode for editing images via imgix.
Emacs Lisp
20
star
20

imgix-java

A Java client library for generating URLs with imgix
Java
19
star
21

django-imgix

Django module to provide imgix template tags and functions
Python
19
star
22

imgix-blueprint

Documentation for creating imgix libraries in different languages
18
star
23

imgix-statamic

An add-on for integrating imgix into Statamic sites
PHP
17
star
24

paperclip-imgix

Paperclip plugin to integrate with Imgix
Ruby
15
star
25

imgix-csharp

A C# client library for generating image URLs with imgix
C#
15
star
26

imgix-go

A Go client library for generating image URLs with imgix
Go
13
star
27

contentful

Browse, search, and add assets into your content quickly and easily via the imgix Asset Manager.
TypeScript
10
star
28

imgix-management-js

A Javascript library that wraps the imgix management API
JavaScript
7
star
29

typescript-imgix-url-params

TypeScript definitions of imgix's URL parameters
TypeScript
5
star
30

eddy

High-performance, maintenence-light, caching library and tools.
C
5
star
31

ix-video

An imgix video custom element that works anywhere
TypeScript
4
star
32

angular

A library for integrating imgix into Angular applications
TypeScript
4
star
33

fontmanager

Command line font manager for OS X
Objective-C
3
star
34

web-components

SDK web components shared across Frontend Frameworks - WIP
TypeScript
3
star
35

go-httpstring

fast http header string parser
Go
2
star
36

go-jobmanager

run subproc pools, on-demand grow and shrink, communicate with length-prefixed response, monitor RSS
Go
2
star
37

strapi-plugin-imgix

Strapi integration for imgix
TypeScript
2
star
38

renovate-config

A shareable Renovate bot configuration for all SDK repos
1
star
39

web-tools

Tools and configurations common to all imgix web projects
JavaScript
1
star
40

imgix-webfolder-router

A simple node.js router to allow multiple Base URLs for imgix Web Folders
JavaScript
1
star
41

nyt-example-app

Demos the imgix srcset API
HTML
1
star
42

sf-commerce-cloud

Use this integration to insert images from imgix's Image Manager into your Salesforce Commerce Cloud websites.
JavaScript
1
star
43

react-native-expo-example-app

Example Expo React Native application using @imgix/js-core to render a responsive image
JavaScript
1
star
44

shopify-integration-guide

Guide for integrating Shopify with imgix
1
star
45

web-tools-ds

Web-tools plugin and pipelines for reading in data assets in a variety of formats and storing them for use in templates
JavaScript
1
star