目录
目录README.md

RemoteImageDimensions

RemoteImageDimensions is a Swift package for determining the dimensions and image type of a remote image without downloading the whole thing. The size of most image formats can be determined after downloading fewer than 30 bytes.

RemoteImageDimensions supports any platform that can run Swift executables: iOS, macOS, Linux, Windows.

Usage

import RemoteImageDimensions

let image = URL(string: "https://pixelfoundry.io/static/logo.png")!

RemoteImage.dimensions(of: image) { result in
    switch result {
        case .success(let dimensions):
            print(dimensions) // Dimensions(width: 606, height: 216, format: .png, bytes: 25)
        case .failure: return
    }
}

Combine Interface

RemoteImageDimensions offers Combine bindings on supported platforms.

import Combine
import RemoteImageDimensions

var cancellable: AnyCancellable?

cancellable = RemoteImage.dimensions(of: image).sink(
    receiveCompletion: { _ in },
    receiveValue: { dimensions in
        print(dimensions) // Dimensions(width: 606, height: 216, format: .png, bytes: 25)
    }
)

Configuration

You can specify the timeout and byte-range headers of network requests using RemoteImage.Configuration. RemoteImageDimensions attempts to download the absolute minimum amount of data to determine the size of the image, which may not always be enough data in the case of non-deterministic formats like JPEG.

RemoteImage.dimensions(of: image, configuration: .init(timeout: 10, byteRange: 0..<100000))

Installation

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/pixel-foundry/remote-image-dimensions", from: "1.0.0")
],
targets: [
    .target(name: "YourTarget", dependencies: ["RemoteImageDimensions"])
]
关于
70.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号