ImageExtract

public class ImageExtract

The class that allows you to get the size of a remote image without downloading.

  • A function to initialize instance.

    Declaration

    Swift

    public init(userAgent: String? = nil,
                maxConnectionsPerHost: Int = 0,
                timeout: TimeInterval = 5,
                chunkSize: ImageChunkSize = .extraLarge)

    Parameters

    userAgent

    A String value to be set in the request header.

    maxConnectionsPerHost

    A Integer value that indicates the maximum number of simultaneous connections to make to a given host.

    timeout

    The timeout interval to use when waiting for additional data.

    chunkSize

    Chunk size limiting buffer size to be downloaded. The default value is ImageChunkSize.extraLarge. (50,000 bytes)

  • A function to get the size of a remote image synchronously.

    Declaration

    Swift

    public func extract(_ request: ImageRequestConvertible) -> (size: CGSize, isFinished: Bool)

    Parameters

    request

    An image url to request. String, URL, and URLRequest are conform to ImageRequestConvertible protocol.

    Return Value

    A tuple value including image size and task result. If the session is cancelled or fails to extract the size of an image, the value of isFinished will be false.

  • A function to get the size of a remote image asynchronously.

    Declaration

    Swift

    public func extract(_ request: ImageRequestConvertible,
                        completion: @escaping (String?, CGSize, Bool) -> Void)

    Parameters

    request

    An image url to request. String, URL, and URLRequest are conform to ImageRequestConvertible protocol.

    completion

    A handler that called when a request is completed. If the session is cancelled or fails to extract the size of an image, the value of isFinished will be false.

  • A function to get the size of an image with preferred width and max height.

    Declaration

    Swift

    func extract(_ request: ImageRequestConvertible,
                 preferredWidth: CGFloat,
                 maxHeight: CGFloat = .greatestFiniteMagnitude) -> (size: CGSize, isFinished: Bool)

    Parameters

    request

    An image url to request. String, URL, and URLRequest are conform to ImageRequestConvertible protocol.

    preferredWidth

    A preferred width to resize.

    maxHeight

    A maximum height to be restricted at resizing.

    Return Value

    A tuple value including image size and task result. If the session is cancelled or fails to extract the size of an image, the value of isFinished will be false.

  • A function to get the size of an image with preferred width and max height.

    Declaration

    Swift

    func extract(_ request: ImageRequestConvertible,
                 preferredWidth: CGFloat,
                 maxHeight: CGFloat = .greatestFiniteMagnitude,
                 completion: @escaping (String?, CGSize, Bool) -> Void)

    Parameters

    request

    An image url to request. String, URL, and URLRequest are conform to ImageRequestConvertible protocol.

    preferredWidth

    A preferred width to resize.

    maxHeight

    A maximum height to be restricted at resizing.

    completion

    A handler that called when a request is completed. If the session is cancelled or fails to extract the size of an image, the value of isFinished will be false.

  • A Boolean value indicating whether download queues are running.

    Declaration

    Swift

    var isQueueRunning: Bool { get }
  • A Integer value indicating the number of running queues.

    Declaration

    Swift

    var queueCount: Int { get }
  • A function to cancel all running queues.

    Declaration

    Swift

    @discardableResult
    func cancelAllQueues() -> Bool

    Return Value

    A Boolean value indicating whether download queues are running.

  • A function to cancel a queue that contains a specific url.

    Declaration

    Swift

    @discardableResult
    func cancelQueue(request: ImageRequestConvertible) -> Bool

    Parameters

    request

    An image url to request. String, URL, and URLRequest are conform to ImageRequestConvertible protocol.

    Return Value

    A Boolean value indicating whether download queues are running.