A Swift client library for generating URLs with imgix

Overview

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

Comments
  • Build issue with pod

    Build issue with pod

    I am using both Objective C and Swift languages in my project and have created a bridging header. My project had been working from a year but upon installing Imgix pod it's giving me build error.

    Error: In an objective c file -> projectName-Swift.h file not found. Can you please help me?

    opened by shashiLBB 8
  • Arabic encoding not working.

    Arabic encoding not working.

    I am using imgix and it crash for following url. "https://imgix.net/live/menu_items/photos/1291/e1eefb34a6b7c415873a0fdd31969af86704f0d/ج_مع_الراب_الرومى.jpg"

    it crashes while buildURL is called.

    opened by Kishanspaceo 6
  • build(spm): add swift package manifest

    build(spm): add swift package manifest

    This PR introduces the addition of a Package.swift manifest, which will allow users to import imgix-swift via the Swift Package Manager. As far as I know, there's no way to test this actually works without the file being checked into the remote repository so I am hoping to get at least one set of experienced eyes on it first. Below are some resources, examples I used when creating this file:

    opened by sherwinski 6
  • Accept NSURL or NSURLCompontents

    Accept NSURL or NSURLCompontents

    It would be convenient if there was a way to build an imgix formatted image from an nsurl.

    UseCase:

    • Our Api returns full image urls for all entities (i.e. https://domain.com/images123.png?possible_query=stuff). It would be nice to have a function on ImgixClient which could somehow take this in as a NSURL or NSURLComponents object, along with an imgix extra parameters formatted dictionary, and then build the final url preserving the original information from the passed in information.

    example: imgixClient.reconstruct(url:NSURL, params:[String:AnyObject]) -> NSURL?

    I have some code which does this in our project, happy to open a PR if you think it's a useful feature.

    opened by jndonald3 6
  • sigabort crash

    sigabort crash

    We got the crash report below. Any ideas what could've caused it?

    Crashed: com.apple.main-thread
    SIGABRT ABORT 0x0000000189f72014
    
    Crashed: com.apple.main-thread
    0  libsystem_kernel.dylib         0x189f72014 __pthread_kill + 8
    1  libsystem_pthread.dylib        0x18a03a450 pthread_kill + 112
    2  libsystem_c.dylib              0x189ee63e0 abort + 140
    3  libsystem_malloc.dylib         0x189fb6a38 _nano_vet_and_size_of_live + 330
    4  libsystem_malloc.dylib         0x189fb7db8 nano_free + 220
    5  CoreFoundation                 0x18af29060 __CFCharacterSetDeallocate + 108
    6  CoreFoundation                 0x18af51a74 _CFRelease + 216
    7  CoreFoundation                 0x18af290a0 __CFCharacterSetDeallocate + 172
    8  CoreFoundation                 0x18af51a74 _CFRelease + 216
    9  libswiftFoundation.dylib       0x100acd914 _TFE10FoundationSS50stringByAddingPercentEncodingWithAllowedCharactersfCSo14NSCharacterSetGSqSS_ + 136
    10 ImgixSwift                     0x1003a08cc String.ixEncodeUriComponent() -> String (String+ImgixSwift.swift:34)
    11 ImgixSwift                     0x10039f958 specialized ImgixClient.buildUrl(String, params : NSDictionary) -> NSURL (ImgixClient.swift:70)
    12 ImgixSwift                     0x10039dd88 ImgixClient.buildUrl(String, params : NSDictionary) -> NSURL (ImgixClient.swift:39)
    13 shoptanga                      0x10003a4e4 specialized static ImageHelper.resizedImageURL(String, width : CGFloat, height : CGFloat)
    

    This is the calling code:

    import Foundation
    import UIKit
    import ImgixSwift
    
    class ImageHelper {
      class func resizedImageURL(sourceURL: String, width:CGFloat, height:CGFloat) -> NSURL {
        let client = ImgixClient.init(host: "tanga1.imgix.net", secureUrlToken: "XXXXXXX")
        return client.buildUrl(
          sourceURL,
          params: [
            "width":    width,
            "height":   height,
            "format":   "auto",
            "lossless": "true",
            "cs": "strip"])
      }
    }
    
    opened by joevandyk 3
  • Add license scan report and status

    Add license scan report and status

    Your FOSSA integration was successful! Attached in this PR is a badge and license report to track scan status in your README.

    Below are docs for integrating FOSSA license checks into your CI:

    opened by fossabot 2
  • chore(release): 1.1.3

    chore(release): 1.1.3

    TTSIA

    1.1.3 (2021-04-13)

    • fix(sanitizePath): encode plus with ixEncodeURI (#35)
    • docs: use circleci build badge
    • docs: update travis badge to travis*ci.com
    opened by luqven 1
  • ci: migrate to circleCI

    ci: migrate to circleCI

    Migrates this project over to CircleCI. This PR also strengthens the tests adding a separate execution for each scheme that imgix-swift is built for (macOS, iOS, and tvOS).

    Addition context: this migration did not work immediately because the previous tests ran on a version of iOS no longer supported by xcodebuild. For now, I have adjusted the tests to use supported versions + devices, but it would be worth further investigating in the future how to config these tests to be more robust.

    opened by sherwinski 1
  • Sort query parameters

    Sort query parameters

    This fixes an issue with building URLs where the same parameter dictionaries may have outputted different URLs depending on their output order during iteration. To avoid this issue, I iterate through a sorted list of the dictionary keys in order to guarantee that building a URL with parameter dictionaries always outputs the same URL.

    opened by nathan-heskia 1
  • Use CharacterSet of Swift and use property setting with closure

    Use CharacterSet of Swift and use property setting with closure

    • Declare ixEncodeUriComponentCharSet as a CharacterSet.
    • Declare ixEncodeUriComponentCharSet with property setting with closure instead of computed property to avoid addCharacters(in:) which is slightly heavy and no need called every time when buildUrl(_:params:) called.
    screen shot 2018-08-30 at 16 20 52
    opened by ikait 1
  • Fix warnings due to use in app extensions.

    Fix warnings due to use in app extensions.

    Xcode gives a warning when including the imgix project and building in an app.

    This is due to use in a component that will be used in an extension. Xcode displays the message "linking against dylib not safe for use in application extensions”. To configure an app extension target to use an embedded framework, set the target’s “Require Only App-Extension-Safe API” build setting to Yes.

    https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html

    opened by shimastripe 1
  • feat(validation): adds domain validation to client

    feat(validation): adds domain validation to client

    Adds domain validation to library.

    Breaking Change

    ImgixClient domains are now validated; must be passed in as a fully qualified domain name and without a protocol or path element.

    enhancement 
    opened by atlawrie 1
Releases(1.1.3)
Owner
imgix
Image Processing at Scale
imgix
The repository for a command line / build pipeline tool for generating colors from a human-readable text file that designers can also use.

ColorPaletteGenerator ColorPaletteGenerator is a tool that takes a human-readable input file describing a color palette, and generates the associated

horseshoe7 0 Dec 7, 2021
TinyPNG4Mac - a client of TinyPNG for Mac

TinyPNG4Mac This is a client of TinyPNG for Mac, with which you can compress pngs without open browser and manually download images, all you need to d

kyleduo 3.2k Dec 31, 2022
Kingfisher is a powerful, pure-Swift library for downloading and caching images from the web

Kingfisher is a powerful, pure-Swift library for downloading and caching images from the web. It provides you a chance to use a pure-Swift way to work

Wei Wang 20.9k Dec 30, 2022
🍁🥓 Lightweight and fast Swift library for image downloading, caching and transformations

MapleBacon Introduction MapleBacon is a lightweight and fast Swift library for downloading and caching images. Example The folder Example contains a s

Jan Gorman 335 Nov 1, 2022
Fast and simple OCR library written in Swift

⛔️ This Project is deprecated and no longer gets maintained! Please use Apple's Vision framework instead of SwiftOCR. It is very fast, accurate and mu

Nicolas Camenisch 4.5k Dec 29, 2022
A high-performance image library for downloading, caching, and processing images in Swift.

Features Asynchronous image downloader with priority queuing Advanced memory and database caching using YapDatabase (SQLite) Guarantee of only one ima

Yap Studios 72 Sep 19, 2022
AYImageKit is a Swift Library for Async Image Downloading, Show Name's Initials and Can View image in Separate Screen.

AYImageKit AYImageKit is a Swift Library for Async Image Downloading. Features Async Image Downloading. Can Show Text Initials. Can have Custom Styles

Adnan Yousaf 11 Jan 10, 2022
A Fast and Complete Swift Drawing Library

FastDraw A Fast and Complete Swift Drawing Library Description FastDraw is a high performance and highly extensible Drawing Library that supports Appl

Collin Zhang 18 Nov 14, 2022
A Swift library for parsing and drawing SVG images to CoreGraphics contexts.

SwiftDraw A Swift library for parsing and drawing SVG images to CoreGraphics contexts. SwiftDraw can also convert an SVG into Swift source code. Usage

Simon Whitty 119 Jan 3, 2023
Swift Image Slider library for iOS

Banana - ImageSlider for Swift Image slider with very simple interface. At a Glance @IBOutlet weak var imageScrollView: UIScrollView! // Here imageArr

Gaurav Katoch 17 Apr 20, 2021
GPU-based media processing library using Metal written in Swift

GPU-based media processing library using Metal written in Swift. Overview MetalAcc is a GPU-Based media processing library that lets you apply GPU-acc

Jiawei Wang 259 Dec 17, 2022
Fast and simple OCR library written in Swift

⛔️ This Project is deprecated and no longer gets maintained! Please use Apple's Vision framework instead of SwiftOCR. It is very fast, accurate and mu

Nicolas Camenisch 4.5k Dec 29, 2022
Cross-platform Swift library for parsing SVGPath strings

Introduction Installation Usage Credits Introduction SVGPath is an open-source parser for the SVG path syntax, making it easy to create CGPaths from t

Nick Lockwood 90 Dec 23, 2022
AlamofireImage is an image component library for Alamofire

AlamofireImage AlamofireImage is an image component library for Alamofire. Features Image Response Serializers UIImage Extensions for Inflation / Scal

Alamofire 3.9k Dec 29, 2022
CTPanoramaView is a library that displays spherical or cylindrical panoramas with touch or motion based controls.

CTPanoramaView is a high-performance library that uses SceneKit to display complete spherical or cylindrical panoramas with touch or motion based controls.

Salih Cihan Tek 1k Jan 2, 2023
Kanvas is an open-source iOS library for adding effects, drawings, text, stickers, and making GIFs from existing media or the camera.

Kanvas Kanvas is an open-source iOS library for adding effects, drawings, text, stickers, and making GIFs from existing media or the camera.

Tumblr 267 Nov 24, 2022
Image filtering UI library like Instagram.

Sharaku Usage How to present SHViewController let imageToBeFiltered = UIImage(named: "targetImage") let vc = SHViewController(image: imageToBeFiltered

Makoto Mori 1.5k Dec 20, 2022
Vision Camera 📸 The Camera library that sees the vision.

Vision Camera ?? The Camera library that sees the vision. npm i react-native-vision-camera npx pod-install Documentation Guides API Ex

Marc Rousavy 3.5k Jan 5, 2023
Shows your photo library grouped by events, to easily export them to your computer

Groupir Shows your photo library grouped by events, to easily export them to your computer Features Currently supported features: reading your photo l

Stanislas Chevallier 0 Dec 15, 2021