Skip to content

SDWebImage/SDWebImageJPEGXLCoder

Repository files navigation

SDWebImageJPEGXLCoder

Version License Platform SwiftPM compatible Carthage compatible

SDWebImageJPEGXLCoder is a coder plugin for SDWebImage, to supports JPEG-XL format.

See: Why JPEG-XL

This coder supports the HDR/SDR decoding, as well as JPEG-XL aniamted image.

Notes

  1. This coder supports animation via UIImageView/NSImageView, no SDAnimatedImageView currently (Because the current coder API need codec supports non-sequential frame decoding, but libjxl does not have. Will remove this limit in SDWebImage 6.0)
  2. This coder does not supports JPEG-XL encoding (Because I have no time :))
  3. Apple's ImageIO supports JPEGXL decoding from iOS 17/tvOS 17/watchOS 10/macOS 14 (via: WWDC2023), so SDWebImage on those platform can also decode JPEGXL images using SDImageIOCoder (but no animated JPEG-XL support)

Requirements

  • iOS 9.0
  • macOS 10.11
  • tvOS 9.0
  • watchOS 2.0
  • visionOS 1.0

Installation

CocoaPods

SDWebImageJPEGXLCoder is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SDWebImageJPEGXLCoder'

Carthage

SDWebImageJPEGXLCoder is available through Carthage.

github "SDWebImage/SDWebImageJPEGXLCoder"

Note: You must use carthage build --use-xcframeworks for integration (because it supports 5 Apple platforms. You can limit platforms you need by using --platform iOS,visionOS)

Swift Package Manager

SDWebImageJPEGXLCoder is available through Swift Package Manager.

let package = Package(
    dependencies: [
        .package(url: "https://github.com/SDWebImage/SDWebImageJPEGXLCoder.git", from: "0.1.0")
    ]
)

Usage

Add Coder

Before using SDWebImage to load JPEGXL images, you need to register the JPEGXL Coder to your coders manager. This step is recommended to be done after your App launch (like AppDelegate method).

  • Objective-C
// Add coder
SDImageJPEGXLCoder *JPEGXLCoder = [SDImageJPEGXLCoder sharedCoder];
[[SDImageCodersManager sharedManager] addCoder:JPEGXLCoder];
  • Swift
// Add coder
let JPEGXLCoder = SDImageJPEGXLCoder.shared
SDImageCodersManager.shared.addCoder(JPEGXLCoder)

Loading

  • Objective-C
// JPEG-XL online image loading
NSURL *JPEGXLURL;
UIImageView *imageView;
[imageView sd_setImageWithURL:JPEGXLURL];
  • Swift
// JPEG-XL online image loading
let JPEGXLURL: URL
let imageView: UIImageView
imageView.sd_setImage(with: JPEGXLURL)

Note: You can also test animated JPEG-XL on UIImageView/NSImageView and WebImage (via SwiftUI port)

Example

To run the example project, clone the repo, and run pod install from the root directory first. Then open SDWebImageJPEGXLCoder.xcworkspace.

This is a demo to show how to use JPEG-XL and animated JPEG-XL images via SDWebImageJPEGXLCoderExample target.

Screenshot

These JPEG-XL images are from JXL Art Gallery

Author

DreamPiggy

License

SDWebImageJPEGXLCoder is available under the MIT license. See the LICENSE file for more info.

Thanks