Skip to content

A Swift library to allows you to extract the size of an image without downloading.

License

Notifications You must be signed in to change notification settings

gumob/ImageExtract

Repository files navigation

Carthage compatible Build Status codecov Platform Language Language Packagist

ImageExtract

A Swift library to allows you to extract the size of an image without downloading.

Requirements

ImageExtract supports multiple platforms

  • iOS 10.0 or later
  • macOS 10.11 or later
  • Swift 5.0 or later

Supported image format

  • JPEG
  • PNG
  • GIF
  • BMP
  • WebP

Installation

Carthage

Add the following to your Cartfile and follow these instructions.

github "gumob/ImageExtract"

Do not forget to include WebP.framework. Otherwise it will fail to build the application.

drawing

Usage

Read the usage and the API reference for detailed information.

Initialization

Just import ImageExtract framework:

import ImageExtract

Synchronous and asynchronous request

Get the size of an image synchronously:

let url: String = "https://example.com/image.jpg"
let extractor: ImageExtract = ImageExtract()
let result: (size: CGSize, isFinished: Bool) = extractor.extract(url)
print(result.size) // (800.0, 600.0)

Get the size of an image asynchronously:

let url: String = "https://example.com/image.jpg"
let extractor: ImageExtract = ImageExtract()
extractor.extract(request) { (url: String?, size: CGSize, isFinished: Bool) in
    print(size) // (800.0, 600.0)
}

Copyright

ImageExtract is released under MIT license, which means you can modify it, redistribute it or use it however you like.