### Install via CocoaPods Source: https://context7.com/sdwebimage/sdwebimagejpegxlcoder/llms.txt Add the dependency to your Podfile and run the installation command. ```ruby # Podfile platform :ios, '9.0' use_frameworks! target 'YourApp' do pod 'SDWebImageJPEGXLCoder' end ``` ```bash # Install dependencies pod install ``` -------------------------------- ### Install via Carthage Source: https://context7.com/sdwebimage/sdwebimagejpegxlcoder/llms.txt Add the repository to your Cartfile and build using xcframeworks. ```text # Cartfile github "SDWebImage/SDWebImageJPEGXLCoder" ``` ```bash # Build with xcframeworks (required for multi-platform support) carthage build --use-xcframeworks # Or limit to specific platforms carthage build --use-xcframeworks --platform iOS,visionOS ``` -------------------------------- ### Install SDWebImageJPEGXLCoder via Carthage Source: https://github.com/sdwebimage/sdwebimagejpegxlcoder/blob/master/README.md Add this line to your Cartfile to install the library using Carthage. Ensure you use --use-xcframeworks for integration. ```bash github "SDWebImage/SDWebImageJPEGXLCoder" ``` -------------------------------- ### Install SDWebImageJPEGXLCoder via CocoaPods Source: https://github.com/sdwebimage/sdwebimagejpegxlcoder/blob/master/README.md Add this line to your Podfile to install the library using CocoaPods. ```ruby pod 'SDWebImageJPEGXLCoder' ``` -------------------------------- ### Install via Swift Package Manager Source: https://context7.com/sdwebimage/sdwebimagejpegxlcoder/llms.txt Include the library as a dependency in your Package.swift file. ```swift // Package.swift let package = Package( name: "YourProject", platforms: [ .iOS(.v9), .macOS(.v10_11), .tvOS(.v9), .watchOS(.v2) ], dependencies: [ .package(url: "https://github.com/SDWebImage/SDWebImageJPEGXLCoder.git", from: "0.2.0") ], targets: [ .target( name: "YourTarget", dependencies: ["SDWebImageJPEGXLCoder"] ) ] ) ``` -------------------------------- ### Install SDWebImageJPEGXLCoder via Swift Package Manager Source: https://github.com/sdwebimage/sdwebimagejpegxlcoder/blob/master/README.md Add the package to your project's dependencies in Package.swift. ```swift let package = Package( dependencies: [ .package(url: "https://github.com/SDWebImage/SDWebImageJPEGXLCoder.git", from: "0.1.0") ] ) ``` -------------------------------- ### Advanced Encoding with libjxl Frame Settings Source: https://context7.com/sdwebimage/sdwebimagejpegxlcoder/llms.txt Exposes underlying libjxl frame settings for fine-grained control over parameters like effort level and brotli compression. Requires importing libjxl headers for specific setting constants. ```objective-c // Objective-C - Advanced encoding with libjxl frame settings #import // For JXL_ENC_FRAME_SETTING_* constants UIImage *image = [UIImage imageNamed:@"photo"]; // Advanced frame settings dictionary // Keys are JxlEncoderFrameSettingId values, values are encoding parameters NSDictionary *frameSetting = @{ @(JXL_ENC_FRAME_SETTING_EFFORT): @(7), // Encoding effort (1-10, higher = slower but better) @(JXL_ENC_FRAME_SETTING_BROTLI_EFFORT): @(11) // Brotli compression effort (0-11) }; NSDictionary *options = @{ SDImageCoderEncodeJXLDistance: @(1.5), // Compression distance SDImageCoderEncodeJXLFrameSetting: frameSetting, // Advanced frame settings SDImageCoderEncodeJXLCodeStreamLevel: @(5), // Codestream level (5 or 10, -1 for auto) SDImageCoderEncodeJXLThreadCount: @(0) // 0 = auto-detect CPU cores }; NSData *data = [[SDImageJPEGXLCoder sharedCoder] encodedDataWithImage:image format:SDImageFormatJPEGXL options:options]; NSLog(@"Advanced encoded JPEG-XL: %lu bytes", (unsigned long)data.length); ``` ```swift // Swift - Advanced encoding with libjxl frame settings import libjxl // For JXL_ENC_FRAME_SETTING_* constants let image = UIImage(named: "photo")! // Advanced frame settings dictionary let frameSetting: [UInt32: Any] = [ JXL_ENC_FRAME_SETTING_EFFORT.rawValue: 7, // Encoding effort (1-10) JXL_ENC_FRAME_SETTING_BROTLI_EFFORT.rawValue: 11 // Brotli effort (0-11) ] let options: [SDImageCoderOption: Any] = [ .encodeJXLDistance: 1.5, .encodeJXLFrameSetting: frameSetting, .encodeJXLCodeStreamLevel: 5, .encodeJXLThreadCount: 0 // Auto-detect ] let data = SDImageJPEGXLCoder.shared.encodedData(with: image, format: .jpegxl, options: options) if let data = data { print("Advanced encoded JPEG-XL: \(data.count) bytes") } ``` -------------------------------- ### Load JPEG-XL Images from URL Source: https://context7.com/sdwebimage/sdwebimagejpegxlcoder/llms.txt Use standard SDWebImage APIs to load JPEG-XL images; the coder automatically handles format detection via file signatures. ```objective-c // Objective-C - Load JPEG-XL image into UIImageView #import UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)]; NSURL *jpegxlURL = [NSURL URLWithString:@"https://example.com/image.jxl"]; [imageView sd_setImageWithURL:jpegxlURL placeholderImage:[UIImage imageNamed:@"placeholder"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { if (error) { NSLog(@"Failed to load JPEG-XL image: %@", error.localizedDescription); } else { NSLog(@"Successfully loaded JPEG-XL image: %@x%@", @(image.size.width), @(image.size.height)); } }]; ``` ```swift // Swift - Load JPEG-XL image into UIImageView import SDWebImage let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) let jpegxlURL = URL(string: "https://example.com/image.jxl")! imageView.sd_setImage(with: jpegxlURL, placeholderImage: UIImage(named: "placeholder")) { image, error, cacheType, url in if let error = error { print("Failed to load JPEG-XL image: \(error.localizedDescription)") } else if let image = image { print("Successfully loaded JPEG-XL image: \(image.size.width)x\(image.size.height)") } } ``` -------------------------------- ### Check JPEG-XL Format Support Source: https://context7.com/sdwebimage/sdwebimagejpegxlcoder/llms.txt Verify if data is a valid JPEG-XL image and check if the coder supports encoding to the JPEG-XL format. ```objective-c // Objective-C - Check format support NSData *unknownData = [NSData dataWithContentsOfFile:@"/path/to/unknown_file"]; // Check if data is JPEG-XL format BOOL canDecode = [[SDImageJPEGXLCoder sharedCoder] canDecodeFromData:unknownData]; if (canDecode) { NSLog(@"Data is valid JPEG-XL format"); UIImage *image = [[SDImageJPEGXLCoder sharedCoder] decodedImageWithData:unknownData options:nil]; } // Check if coder can encode to JPEG-XL BOOL canEncode = [[SDImageJPEGXLCoder sharedCoder] canEncodeToFormat:SDImageFormatJPEGXL]; NSLog(@"Can encode JPEG-XL: %@", canEncode ? @"YES" : @"NO"); ``` ```swift // Swift - Check format support let unknownData = try! Data(contentsOf: URL(fileURLWithPath: "/path/to/unknown_file")) // Check if data is JPEG-XL format let canDecode = SDImageJPEGXLCoder.shared.canDecode(from: unknownData) if canDecode { print("Data is valid JPEG-XL format") let image = SDImageJPEGXLCoder.shared.decodedImage(with: unknownData, options: nil) } // Check if coder can encode to JPEG-XL let canEncode = SDImageJPEGXLCoder.shared.canEncode(to: .jpegxl) print("Can encode JPEG-XL: \(canEncode)") ``` -------------------------------- ### Register JPEG-XL Coder at App Launch Source: https://context7.com/sdwebimage/sdwebimagejpegxlcoder/llms.txt Register the coder with the SDImageCodersManager during application startup to enable automatic JPEG-XL format detection. ```objective-c // Objective-C - Register coder at app launch #import - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Register the JPEG-XL coder SDImageJPEGXLCoder *JPEGXLCoder = [SDImageJPEGXLCoder sharedCoder]; [[SDImageCodersManager sharedManager] addCoder:JPEGXLCoder]; return YES; } ``` ```swift // Swift - Register coder at app launch import SDWebImageJPEGXLCoder func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Register the JPEG-XL coder let jpegxlCoder = SDImageJPEGXLCoder.shared SDImageCodersManager.shared.addCoder(jpegxlCoder) return true } ``` -------------------------------- ### Load JPEG-XL Image Online (Swift) Source: https://github.com/sdwebimage/sdwebimagejpegxlcoder/blob/master/README.md Load a JPEG-XL image from a URL into a UIImageView using SDWebImage. Ensure the JPEGXL coder is registered. ```swift // JPEG-XL online image loading let JPEGXLURL: URL let imageView: UIImageView imageView.sd_setImage(with: JPEGXLURL) ``` -------------------------------- ### Register JPEGXL Coder (Swift) Source: https://github.com/sdwebimage/sdwebimagejpegxlcoder/blob/master/README.md Register the shared JPEGXL coder with the SDImageCodersManager to enable JPEG-XL image handling. This should be done after your app launches. ```swift // Add coder let JPEGXLCoder = SDImageJPEGXLCoder.shared SDImageCodersManager.shared.addCoder(JPEGXLCoder) ``` -------------------------------- ### Load JPEG-XL Image Online (Objective-C) Source: https://github.com/sdwebimage/sdwebimagejpegxlcoder/blob/master/README.md Load a JPEG-XL image from a URL into a UIImageView using SDWebImage. Ensure the JPEGXL coder is registered. ```objective-c // JPEG-XL online image loading NSURL *JPEGXLURL; UIImageView *imageView; [imageView sd_setImageWithURL:JPEGXLURL]; ``` -------------------------------- ### Register JPEGXL Coder (Objective-C) Source: https://github.com/sdwebimage/sdwebimagejpegxlcoder/blob/master/README.md Register the shared JPEGXL coder with the SDImageCodersManager to enable JPEG-XL image handling. This should be done after your app launches. ```objective-c // Add coder SDImageJPEGXLCoder *JPEGXLCoder = [SDImageJPEGXLCoder sharedCoder]; [[SDImageCodersManager sharedManager] addCoder:JPEGXLCoder]; ``` -------------------------------- ### Encode Animated JPEG-XL Images (Swift) Source: https://github.com/sdwebimage/sdwebimagejpegxlcoder/blob/master/README.md This Swift code demonstrates encoding multiple images into an animated JPEG-XL file. Each frame requires an image and a duration. ```swift // Animated encoding var frames: [SDImageFrame] = [] for i in 0.. *frames = [NSMutableArray array]; for (size_t i = 0; i < images.count; i++) { SDImageFrame *frame = [SDImageFrame frameWithImage:images[i] duration:0.1]; [frames appendObject:frame]; } NSData *animatedData = [[SDImageJPEGXLCoder sharedCoder] encodedDataWithFrames:frames loopCount:0 format:SDImageFormatJPEGXL options:nil]; ``` -------------------------------- ### Decode JPEG-XL Data Directly Source: https://context7.com/sdwebimage/sdwebimagejpegxlcoder/llms.txt Perform manual decoding of binary JPEG-XL data into image objects, with support for custom options like scaling and thumbnail generation. ```objective-c // Objective-C - Decode JPEG-XL data directly NSData *jpegxlData = [NSData dataWithContentsOfFile:@"/path/to/image.jxl"]; // Basic decoding UIImage *image = [[SDImageJPEGXLCoder sharedCoder] decodedImageWithData:jpegxlData options:nil]; // Decoding with options (scale factor, first frame only for animations) NSDictionary *options = @{ SDImageCoderDecodeScaleFactor: @(2.0), // 2x scale SDImageCoderDecodeFirstFrameOnly: @YES, // Only decode first frame of animated JXL SDImageCoderDecodeThumbnailPixelSize: @(CGSizeMake(100, 100)), // Generate thumbnail SDImageCoderDecodePreserveAspectRatio: @YES // Preserve aspect ratio for thumbnail }; UIImage *scaledImage = [[SDImageJPEGXLCoder sharedCoder] decodedImageWithData:jpegxlData options:options]; NSLog(@"Decoded image size: %@", NSStringFromCGSize(scaledImage.size)); ``` ```swift // Swift - Decode JPEG-XL data directly let jpegxlData = try! Data(contentsOf: URL(fileURLWithPath: "/path/to/image.jxl")) // Basic decoding let image = SDImageJPEGXLCoder.shared.decodedImage(with: jpegxlData, options: nil) // Decoding with options let options: [SDImageCoderOption: Any] = [ .decodeScaleFactor: 2.0, .decodeFirstFrameOnly: true, .decodeThumbnailPixelSize: CGSize(width: 100, height: 100), .decodePreserveAspectRatio: true ] let scaledImage = SDImageJPEGXLCoder.shared.decodedImage(with: jpegxlData, options: options) if let image = scaledImage { print("Decoded image size: \(image.size)") } ``` -------------------------------- ### Encode Image to JPEG-XL (Objective-C) Source: https://context7.com/sdwebimage/sdwebimagejpegxlcoder/llms.txt Encodes a UIImage to JPEG-XL format. Supports default, lossy (with quality 0.0-1.0), and lossless encoding. Use `SDImageCoderEncodeCompressionQuality` for lossy and `SDImageCoderEncodeJXLLoseless` for lossless. ```Objective-C // Objective-C - Encode image to JPEG-XL UIImage *image = [UIImage imageNamed:@"photo"]; // Basic encoding (default quality) NSData *jpegxlData = [[SDImageJPEGXLCoder sharedCoder] encodedDataWithImage:image format:SDImageFormatJPEGXL options:nil]; // Lossy encoding with compression quality (0.0 to 1.0) NSDictionary *lossyOptions = @{ SDImageCoderEncodeCompressionQuality: @(0.8) // 80% quality }; NSData *lossyData = [[SDImageJPEGXLCoder sharedCoder] encodedDataWithImage:image format:SDImageFormatJPEGXL options:lossyOptions]; // Lossless encoding NSDictionary *losslessOptions = @{ SDImageCoderEncodeJXLLoseless: @YES }; NSData *losslessData = [[SDImageJPEGXLCoder sharedCoder] encodedDataWithImage:image format:SDImageFormatJPEGXL options:losslessOptions]; // Save to file [jpegxlData writeToFile:@"/path/to/output.jxl" atomically:YES]; NSLog(@"Encoded JPEG-XL size: %lu bytes", (unsigned long)jpegxlData.length); ``` -------------------------------- ### Encode with JXL Distance Parameter (Objective-C) Source: https://context7.com/sdwebimage/sdwebimagejpegxlcoder/llms.txt Encodes an image to JPEG-XL using the JXL distance parameter for precise compression control. This parameter overrides compression quality. Values range from 0.0 (lossless) to 25.0, with 1.0 being visually lossless. ```Objective-C // Objective-C - Encode with JXL distance UIImage *image = [UIImage imageNamed:@"photo"]; // Distance-based encoding (overrides compression quality) // 0.0 = mathematically lossless, 1.0 = visually lossless, recommended: 0.5-3.0 NSDictionary *options = @{ SDImageCoderEncodeJXLDistance: @(1.0) // Visually lossless }; NSData *data = [[SDImageJPEGXLCoder sharedCoder] encodedDataWithImage:image format:SDImageFormatJPEGXL options:options]; // High compression (lower quality, smaller file) NSDictionary *highCompressionOptions = @{ SDImageCoderEncodeJXLDistance: @(3.0) }; NSData *smallerData = [[SDImageJPEGXLCoder sharedCoder] encodedDataWithImage:image format:SDImageFormatJPEGXL options:highCompressionOptions]; NSLog(@"Visually lossless: %lu bytes, High compression: %lu bytes", (unsigned long)data.length, (unsigned long)smallerData.length); ``` -------------------------------- ### Encode with JXL Distance Parameter (Swift) Source: https://context7.com/sdwebimage/sdwebimagejpegxlcoder/llms.txt Encodes an image to JPEG-XL in Swift using the JXL distance parameter for precise compression control. This parameter overrides compression quality. Values range from 0.0 (lossless) to 25.0, with 1.0 being visually lossless. ```Swift // Swift - Encode with JXL distance let image = UIImage(named: "photo")! // Distance-based encoding let options: [SDImageCoderOption: Any] = [ .encodeJXLDistance: 1.0 // Visually lossless ] let data = SDImageJPEGXLCoder.shared.encodedData(with: image, format: .jpegxl, options: options) // High compression let highCompressionOptions: [SDImageCoderOption: Any] = [ .encodeJXLDistance: 3.0 ] let smallerData = SDImageJPEGXLCoder.shared.encodedData(with: image, format: .jpegxl, options: highCompressionOptions) print("Visually lossless: \(data?.count ?? 0) bytes, High compression: \(smallerData?.count ?? 0) bytes") ``` -------------------------------- ### Advanced JPEG-XL Encoding Options (Objective-C) Source: https://github.com/sdwebimage/sdwebimagejpegxlcoder/blob/master/README.md Control advanced JPEG-XL encoding parameters like effort and distance using this Objective-C snippet. Frame-specific settings can be applied. ```objective-c NSDictionary *frameSetting = @{ @(JXL_ENC_FRAME_SETTING_EFFORT) : @(10), @(JXL_ENC_FRAME_SETTING_BROTLI_EFFORT) : @(11) }; NSData *data = [SDImageJPEGXLCoder.sharedCoder encodedDataWithImage:image format:SDImageFormatJPEGXL options:@{ SDImageCoderEncodeJXLDistance : @(3.0), // jxl -distance SDImageCoderEncodeJXLFrameSetting : frameSetting, // jxl -effort }]; ``` -------------------------------- ### Encode Image to JPEG-XL Data (Swift) Source: https://github.com/sdwebimage/sdwebimagejpegxlcoder/blob/master/README.md Encode a UIImage into JPEG-XL formatted Data using the shared JPEGXL coder. Supports quality options. ```swift // JPEGXL image encoding let image: UIImage let JPEGXLData = SDImageJPEGXLCoder.shared.encodedData(with: image, format: .jpegxl, options: nil) // Encode Quality let lossyJPEGXLData = SDImageJPEGXLCoder.shared.encodedData(with: image, format: .jpegxl, options: [.encodeCompressionQuality: 0.1]) // [0, 1] compression quality ``` -------------------------------- ### Encode Image to JPEG-XL (Swift) Source: https://context7.com/sdwebimage/sdwebimagejpegxlcoder/llms.txt Encodes a UIImage to JPEG-XL format in Swift. Supports default, lossy (with quality 0.0-1.0), and lossless encoding. Use `.encodeCompressionQuality` for lossy and `.encodeJXLLoseless` for lossless. ```Swift // Swift - Encode image to JPEG-XL let image = UIImage(named: "photo")! // Basic encoding let jpegxlData = SDImageJPEGXLCoder.shared.encodedData(with: image, format: .jpegxl, options: nil) // Lossy encoding with compression quality let lossyOptions: [SDImageCoderOption: Any] = [ .encodeCompressionQuality: 0.8 // 80% quality ] let lossyData = SDImageJPEGXLCoder.shared.encodedData(with: image, format: .jpegxl, options: lossyOptions) // Lossless encoding let losslessOptions: [SDImageCoderOption: Any] = [ .encodeJXLLoseless: true ] let losslessData = SDImageJPEGXLCoder.shared.encodedData(with: image, format: .jpegxl, options: losslessOptions) if let data = jpegxlData { try? data.write(to: URL(fileURLWithPath: "/path/to/output.jxl")) print("Encoded JPEG-XL size: \(data.count) bytes") } ``` -------------------------------- ### Decode JPEG-XL Image Data (Swift) Source: https://github.com/sdwebimage/sdwebimagejpegxlcoder/blob/master/README.md Decode JPEG-XL image data into a UIImage object using the shared JPEGXL coder. ```swift // JPEGXL image decoding let JPEGXLData: Data let image = SDImageJPEGXLCoder.shared.decodedImage(with: data, options: nil) ``` -------------------------------- ### Encode Image to JPEG-XL Data (Objective-C) Source: https://github.com/sdwebimage/sdwebimagejpegxlcoder/blob/master/README.md Encode a UIImage into JPEG-XL formatted NSData using the shared JPEGXL coder. Supports quality options. ```objective-c // JPEGXL image encoding UIImage *image; NSData *JPEGXLData = [[SDImageJPEGXLCoder sharedCoder] encodedDataWithImage:image format:SDImageFormatJPEGXL options:nil]; // Encode Quality NSData *lossyJPEGXLData = [[SDImageJPEGXLCoder sharedCoder] encodedDataWithImage:image format:SDImageFormatJPEGXL options:@{SDImageCoderEncodeCompressionQuality : @(0.1)}]; // [0, 1] compression quality ``` -------------------------------- ### Decode JPEG-XL Image Data (Objective-C) Source: https://github.com/sdwebimage/sdwebimagejpegxlcoder/blob/master/README.md Decode JPEG-XL image data into a UIImage object using the shared JPEGXL coder. ```objective-c // JPEGXL image decoding NSData *JPEGXLData; UIImage *image = [[SDImageJPEGXLCoder sharedCoder] decodedImageWithData:JPEGXLData options:nil]; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.