HPImageResizer Documentation Beta

Class Image​Resizer

public class ImageResizer 

A class that can scale and resize images in a high-performant way

Initializers

init(source​URL:​)

public init(sourceURL: URL) throws 

Initialises a new ImageResizer instance with that loads the passed in image URL

Parameters

source​URL URL

The URL of the source image that is supposed to be resized or scaled

Throws

Throws if there's no existing file (that is also an image) at the passed URL or when the image properties could not be read

Methods

resize​Image(to:​)

public func resizeImage(to size: CGSize) throws -> CGImage 

Resizes the loaded image

Parameters

size CGSize

The desired target size of the resized image

Throws

Throws if the image could not be resized correctly

Returns

The resized image

resize​Image(to:​destination​URL:​format:​)

public func resizeImage(to size: CGSize, destinationURL: URL, format: ImageFormat) throws 

Resizes the loaded image and writes it to the specified destination URL

Parameters

size CGSize

The desired target size of the resized image

destination​URL URL

The URL the resized image should be written to

format Image​Format

The format that the resized image should be written in

Throws

Throws if the image could not be resized correctly or writing to the destination URL failed

scale​Image(to:​)

public func scaleImage(to scale: CGFloat) throws -> CGImage 

Scales the loaded image by a factor

Parameters

scale CGFloat

The desired relative scale of the scaled image

Throws

Throws if the image could not be scaled correctly

Returns

The scaled image

scale​Image(to:​destination​URL:​format:​)

public func scaleImage(to scale: CGFloat, destinationURL: URL, format: ImageFormat) throws 

Scales the loaded image and writes it to the specified destination URL

Parameters

scale CGFloat

The desired relative scale of the scaled image

destination​URL URL

The URL the scaled image should be written to

format Image​Format

The format that the scaled image should be written in

Throws

Throws if the image could not be scaled correctly or writing to the destination URL failed