### Install SDWebImageAVIFCoder with Carthage Source: https://github.com/sdwebimage/sdwebimageavifcoder/blob/master/README.md Add the SDWebImageAVIFCoder repository to your Cartfile for Carthage integration. Carthage only supports the 'aom' codec. ```shell github "SDWebImage/SDWebImageAVIFCoder" ``` -------------------------------- ### Install SDWebImageAVIFCoder with CocoaPods Source: https://github.com/sdwebimage/sdwebimageavifcoder/blob/master/README.md Install the SDWebImageAVIFCoder pod. Default uses the 'aom' AV1 codec. Subspecs can be used to select alternative codecs like rav1e, dav1d, libgav1, or SVT-AV1. ```ruby pod 'SDWebImageAVIFCoder' ``` ```ruby pod 'SDWebImageAVIFCoder' pod 'libavif', :subspecs => [ 'libdav1d', 'librav1e' ] ``` ```ruby pod 'SDWebImageAVIFCoder' pod 'libavif', :subspecs => [ 'libgva1', 'SVT-AV1' ] ``` -------------------------------- ### Install SDWebImageAVIFCoder with Swift Package Manager Source: https://github.com/sdwebimage/sdwebimageavifcoder/blob/master/README.md Add the SDWebImageAVIFCoder Swift Package Manager dependency. The SPM version only supports the 'aom' codec. ```swift let package = Package( dependencies: [ .package(url: "https://github.com/SDWebImage/SDWebImageAVIFCoder.git", from: "0.5") ] ) ``` -------------------------------- ### Choose AVIF Codec at Runtime (Swift) Source: https://github.com/sdwebimage/sdwebimageavifcoder/blob/master/README.md Force the use of specific AV1 codecs for decoding and encoding AVIF images. Pass these options at the UI level when setting an image. ```swift let decodeOptions: [SDImageCoderOption: Any] = [.avifDecodeCodecChoice: AVIF_CODEC_CHOICE_AOM.rawValue] let encodeOptions = [SDImageCoderOption: Any] = [.avifEncodeCodecChoice: AVIF_CODEC_CHOICE_RAV1E.rawValue] // Pass from UI level options imagView.sd_setImage(with: url, placeholderImage: nil, options: [], context: [.imageDecodeOptions: decodeOptions, .imageEncodeOptions: encodeOptions], progress: nil, completed: nil) ``` -------------------------------- ### Choose AVIF Codec at Runtime (Objective-C) Source: https://github.com/sdwebimage/sdwebimageavifcoder/blob/master/README.md Force the use of specific AV1 codecs for decoding and encoding AVIF images. Pass these options at the UI level when setting an image. ```objective-c NSDictionary *decodeOptions = [SDImageCoderAVIFDecodeCodecChoice: @(AVIF_CODEC_CHOICE_AOM)]; NSDictionary *encodeOptions = [SDImageCoderAVIFEncodeCodecChoice: @(AVIF_CODEC_CHOICE_RAV1E)]; // Pass from UI level options [imageView sd_setImageWithURL:url placeholderImage:nil options:0 context:@{SDWebImageContextImageDecodeOptions: decodeOptions, SDWebImageContextImageEncodeOptions: encodeOptions} progress:nil completed:nil]; ``` -------------------------------- ### CocoaPods: Use libavif with libgav1 codec Source: https://github.com/sdwebimage/sdwebimageavifcoder/blob/master/README.md To enable libavif support with the libgav1 AV1 decoder using CocoaPods, specify the 'libavif/libgav1' subspec. ```ruby pod 'libavif/libgav1' ``` -------------------------------- ### CocoaPods: Use libavif with dav1d codec Source: https://github.com/sdwebimage/sdwebimageavifcoder/blob/master/README.md For CocoaPods users, to integrate libavif with the dav1d AV1 codec, use the 'libavif/libdav1d' subspec. ```ruby pod 'libavif/libdav1d' ``` -------------------------------- ### CocoaPods: Use libavif with rav1e encoder Source: https://github.com/sdwebimage/sdwebimageavifcoder/blob/master/README.md For CocoaPods integration with the rav1e AV1 encoder, use the 'libavif/librav1e' subspec. Note that this subspec uses a pre-built static-linking binary. ```ruby pod 'libavif/librav1e' ``` -------------------------------- ### Add SDImageAVIFCoder to Coders Manager (Swift) Source: https://github.com/sdwebimage/sdwebimageavifcoder/blob/master/README.md Register the shared SDImageAVIFCoder instance with the SDImageCodersManager to enable AVIF image loading. Then use the standard image loading methods. ```swift let AVIFCoder = SDImageAVIFCoder.shared SDImageCodersManager.shared.addCoder(AVIFCoder) let imageView: UIImageView imagView.sd_setImage(with: url) ``` -------------------------------- ### CocoaPods: Static Framework Linkage for librav1e Source: https://github.com/sdwebimage/sdwebimageavifcoder/blob/master/README.md When using the librav1e encoder with CocoaPods, especially for framework package formats, ensure static linkage is specified. This is required because librav1e on CocoaPods uses a pre-built static-linking binary. ```ruby use_frameworks! :linkage => :static ``` -------------------------------- ### CocoaPods: Use libavif with aom codec Source: https://github.com/sdwebimage/sdwebimageavifcoder/blob/master/README.md To use the libavif library with the aom AV1 codec via CocoaPods, specify the 'libavif/liaom' subspec. ```ruby pod 'libavif/liaom' ``` -------------------------------- ### Decode AVIF Thumbnail (Objective-C) Source: https://github.com/sdwebimage/sdwebimageavifcoder/blob/master/README.md Decode a specific thumbnail size from AVIF image data. This is useful for displaying previews efficiently. Requires version 0.10.0+. ```objective-c // AVIF thumbnail image decoding NSData *avifData; CGSize thumbnailSize = CGSizeMake(300, 300); UIImage *thumbnailImage = [[SDImageAVIFCoder sharedCoder] decodedImageWithData:avifData options:@{SDImageCoderDecodeThumbnailPixelSize : @(thumbnailSize)}]; ``` -------------------------------- ### Add SDImageAVIFCoder to Coders Manager (Objective-C) Source: https://github.com/sdwebimage/sdwebimageavifcoder/blob/master/README.md Register the shared SDImageAVIFCoder instance with the SDImageCodersManager to enable AVIF image loading. Then use the standard image loading methods. ```objective-c SDImageAVIFCoder *AVIFCoder = SDImageAVIFCoder.sharedCoder; [[SDImageCodersManager sharedManager] addCoder:AVIFCoder]; UIImageView *imageView; [imageView sd_setImageWithURL:url]; ``` -------------------------------- ### Decode AVIF Thumbnail (Swift) Source: https://github.com/sdwebimage/sdwebimageavifcoder/blob/master/README.md Decode a specific thumbnail size from AVIF image data. This is useful for displaying previews efficiently. Requires version 0.10.0+. ```swift // AVIF thumbnail image decoding let avifData: Data let thumbnailSize = CGSize(width: 300, height: 300) let image = SDImageAVIFCoder.shared.decodedImage(with: data, options: [.decodeThumbnailPixelSize: thumbnailSize]) ``` -------------------------------- ### Encode AVIF Image (Objective-C) Source: https://github.com/sdwebimage/sdwebimageavifcoder/blob/master/README.md Encodes a UIImage into AVIF format using SDImageAVIFCoder. Supports specifying compression quality. ```objective-c // AVIF image encoding UIImage *image; NSData *avifData = [[SDImageAVIFCoder sharedCoder] encodedDataWithImage:image format:SDImageFormatAVIF options:nil]; // Encode Quality NSData *lossyAVIFData = [[SDImageAVIFCoder sharedCoder] encodedDataWithImage:image format:SDImageFormatAVIF options:@{SDImageCoderEncodeCompressionQuality : @(0.1)}]; // [0, 1] compression quality ``` -------------------------------- ### Encode AVIF Image (Swift) Source: https://github.com/sdwebimage/sdwebimageavifcoder/blob/master/README.md Encodes a UIImage into AVIF format using SDImageAVIFCoder. Supports specifying compression quality. ```swift // AVIF image encoding let image: UIImage let avifData = SDImageAVIFCoder.shared.encodedData(with: image, format: .avif, options: nil) // Encode Quality let lossyAVIFData = SDImageAVIFCoder.shared.encodedData(with: image, format: .avif, options: [.encodeCompressionQuality: 0.1]) // [0, 1] compression quality ``` -------------------------------- ### Thumbnail Encoding AVIF Image (Objective-C) Source: https://github.com/sdwebimage/sdwebimageavifcoder/blob/master/README.md Encodes a UIImage into AVIF format with a specified maximum pixel size for thumbnails. Requires the aom codec encoder. ```objective-c // AVIF image thumbnail encoding UIImage *image; NSData *thumbnailAVIFData = [[SDImageAVIFCoder sharedCoder] encodedDataWithImage:image format:SDImageFormatAVIF options:@{SDImageCoderEncodeMaxPixelSize : @(CGSizeMake(200, 200))}]; // encoding max pixel size ``` -------------------------------- ### Thumbnail Encoding AVIF Image (Swift) Source: https://github.com/sdwebimage/sdwebimageavifcoder/blob/master/README.md Encodes a UIImage into AVIF format with a specified maximum pixel size for thumbnails. Requires the aom codec encoder. ```swift // AVIF image thumbnail encoding let image: UIImage let thumbnailAVIFData = SDImageAVIFCoder.shared.encodedData(with: image, format: .AVIF, options: [.encodeMaxPixelSize: CGSize(width: 200, height: 200)]) // encoding max pixel size ``` -------------------------------- ### Decode AVIF Image Data (Objective-C) Source: https://github.com/sdwebimage/sdwebimageavifcoder/blob/master/README.md Decode raw AVIF image data into a UIImage object using the shared AVIF coder. Options can be passed to customize decoding. ```objective-c // AVIF image decoding NSData *avifData; UIImage *image = [[SDImageAVIFCoder sharedCoder] decodedImageWithData:avifData options:nil]; ``` -------------------------------- ### Decode AVIF Image Data (Swift) Source: https://github.com/sdwebimage/sdwebimageavifcoder/blob/master/README.md Decode raw AVIF image data into a UIImage object using the shared AVIF coder. Options can be passed to customize decoding. ```swift // AVIF image decoding let avifData: Data let image = SDImageAVIFCoder.shared.decodedImage(with: data, options: nil) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.