Photo

@objcMembers
@objc(PESDKPhoto)
public final class Photo : NSObject

An object that wraps different types of image data.

The Photo class currently supports URL, Data and UIImage as sources for photos. The image type to choose depends on where the image comes from:

  • Use URL for image files on disk.
  • Use Data for images from the web.
  • Use UIImage only if the image was already used in the UI.

Using URL or Data will have the least amount of memory footprint because we will do the image scaling without reading the full image if possible. We also try to do this with UIImage, however if the instance of UIImage represents a wide-color image we will have to read the full image which can lead to memory pressure for large images.

If memory is still an issue when using Data objects, it is recommended that you write the data to disk and initialize a Photo with a file url instead.

When URL or Data is used we are also able to keep any associated EXIF data, which UIImage does not support.

The data format can be any image format that can be read by iOS, for example PNG, JPEG or HEIF.

Note

You don’t have to pre-scale your image because we’re already doing any work that is necessary.
  • url

    The url that this photo was initialized with if any.

    Declaration

    Swift

    public let url: URL?
  • The data object that this photo was initialized with if any.

    Declaration

    Swift

    public let data: Data?
  • The image object that this photo was initialized with if any.

    Declaration

    Swift

    public let image: UIImage?
  • Creates a new photo from the given url.

    Declaration

    Swift

    @objc(initWithURL:)
    public init(url: URL)

    Parameters

    url

    The url to the image on disk.

  • Creates a new photo from the given data.

    Declaration

    Swift

    public init(data: Data)

    Parameters

    data

    The data of the image.

  • Creates a new photo from the given UIImage object.

    Declaration

    Swift

    public init(image: UIImage)

    Parameters

    image

    The UIImage instance.