Kingfisher Documentation

Structure Format​Indicated​Cache​Serializer

public struct FormatIndicatedCacheSerializer: CacheSerializer  

FormatIndicatedCacheSerializer lets you indicate an image format for serialized caches.

It could serialize and deserialize PNG, JPEG and GIF images. For image other than these formats, a normalized pngRepresentation will be used.

Example:

let profileImageSize = CGSize(width: 44, height: 44)

// A round corner image.
let imageProcessor = RoundCornerImageProcessor(
    cornerRadius: profileImageSize.width / 2, targetSize: profileImageSize)

let optionsInfo: KingfisherOptionsInfo = [
    .cacheSerializer(FormatIndicatedCacheSerializer.png), 
    .processor(imageProcessor)]

A URL pointing to a JPEG image.
let url = URL(string: "https://example.com/image.jpg")!

// Image will be always cached as PNG format to preserve alpha channel for round rectangle.
// So when you load it from cache again later, it will be still round cornered.
// Otherwise, the corner part would be filled by white color (since JPEG does not contain an alpha channel).
imageView.kf.setImage(with: url, options: optionsInfo)
%153 FormatIndicatedCacheSerializer FormatIndicatedCacheSerializer CacheSerializer CacheSerializer FormatIndicatedCacheSerializer->CacheSerializer

Conforms To

CacheSerializer

An CacheSerializer is used to convert some data to an image object after retrieving it from disk storage, and vice versa, to convert an image to data object for storing to the disk storage.

Properties

png

public static let png  

A FormatIndicatedCacheSerializer which converts image from and to PNG format. If the image cannot be represented by PNG format, it will fallback to its real format which is determined by original data.

jpeg

public static let jpeg  

A FormatIndicatedCacheSerializer which converts image from and to JPEG format. If the image cannot be represented by JPEG format, it will fallback to its real format which is determined by original data. The compression quality is 1.0 when using this serializer. If you need to set a customized compression quality, use jpeg(compressionQuality:).

gif

public static let gif  

A FormatIndicatedCacheSerializer which converts image from and to GIF format. If the image cannot be represented by GIF format, it will fallback to its real format which is determined by original data.

Methods

jpeg(compression​Quality:​)

public static func jpeg(compressionQuality: CGFloat) -> FormatIndicatedCacheSerializer  

A FormatIndicatedCacheSerializer which converts image from and to JPEG format with a settable compression quality. If the image cannot be represented by JPEG format, it will fallback to its real format which is determined by original data.

Parameters

compression​Quality CGFloat

The compression quality when converting image to JPEG data.

data(with:​original:​)

public func data(with image: KFCrossPlatformImage, original: Data?) -> Data?  

Creates data which represents the given image under a format.

image(with:​options:​)

public func image(with data: Data, options: KingfisherParsedOptionsInfo) -> KFCrossPlatformImage?  

Same implementation as DefaultCacheSerializer.