Skip to content

Repository files navigation

CI codecov SPM compatible Carthage compatible Platform Language License

ImageExtract

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

Requirements

  • iOS 15.0 or later
  • macOS 12.0 or later
  • Swift 5.9 or later (Xcode 15 or later)

Supported image format

  • JPEG
  • PNG
  • GIF
  • BMP
  • WebP

All formats including WebP are decoded by parsing the image header directly. No external dependencies are required.

Installation

Swift Package Manager

In Xcode, choose File > Add Package Dependencies… and enter:

https://github.com/futamura/ImageExtract.git

Or add the following to your Package.swift:

dependencies: [
    .package(url: "https://github.com/futamura/ImageExtract.git", from: "3.0.0")
]

Carthage

Add the following to your Cartfile and follow these instructions.

github "futamura/ImageExtract"

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(url) { (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.

About

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

Topics

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages