A Swift library to allows you to extract the size of an image without downloading.
- iOS 15.0 or later
- macOS 12.0 or later
- Swift 5.9 or later (Xcode 15 or later)
- JPEG
- PNG
- GIF
- BMP
- WebP
All formats including WebP are decoded by parsing the image header directly. No external dependencies are required.
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")
]Add the following to your Cartfile and follow these instructions.
github "futamura/ImageExtract"
Read the usage and the API reference for detailed information.
Just import ImageExtract framework:
import ImageExtractGet 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)
}ImageExtract is released under MIT license, which means you can modify it, redistribute it or use it however you like.