https://github.com/SDWebImage/SDWebImageJPEGXLCoder
A SDWebImage coder plugin to support JPEG-XL image
https://github.com/SDWebImage/SDWebImageJPEGXLCoder
ios jpeg jpeg-xl macos sdwebimage swift-package-manager tvos visionos watchos
Last synced: about 1 month ago
JSON representation
A SDWebImage coder plugin to support JPEG-XL image
- Host: GitHub
- URL: https://github.com/SDWebImage/SDWebImageJPEGXLCoder
- Owner: SDWebImage
- License: mit
- Created: 2024-02-26T08:01:25.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-02-28T16:57:46.000Z (about 1 year ago)
- Last Synced: 2024-10-29T21:05:36.143Z (6 months ago)
- Topics: ios, jpeg, jpeg-xl, macos, sdwebimage, swift-package-manager, tvos, visionos, watchos
- Language: Objective-C
- Homepage:
- Size: 284 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SDWebImageJPEGXLCoder
[](http://cocoapods.org/pods/SDWebImageJPEGXLCoder)
[](http://cocoapods.org/pods/SDWebImageJPEGXLCoder)
[](http://cocoapods.org/pods/SDWebImageJPEGXLCoder)
[](https://swift.org/package-manager/)
[](https://github.com/SDWebImage/SDWebImageJPEGXLCoder)SDWebImageJPEGXLCoder is a coder plugin for SDWebImage, to supports [JPEG-XL](https://jpeg.org/jpegxl/) format.
See: [Why JPEG-XL](https://jpegxl.info/why-jxl.html)
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. Apple's ImageIO supports JPEGXL decoding from iOS 17/tvOS 17/watchOS 10/macOS 14 (via: [WWDC2023](https://developer.apple.com/videos/play/wwdc2023/10122/)), so SDWebImage on those platform can also decode JPEGXL images using `SDImageIOCoder` (but no animated JPEG-XL support)
3. From v0.2.0, this coder support JXL encoding, including HDR, static JXL, animated JXL encoding as well (a huge work...)## Requirements
+ iOS 9.0
+ macOS 10.11
+ tvOS 9.0
+ watchOS 2.0
+ visionOS 1.0## Installation
#### CocoaPods
SDWebImageJPEGXLCoder is available through [CocoaPods](http://cocoapods.org). To install it, simply add the following line to your Podfile:
```ruby
pod 'SDWebImageJPEGXLCoder'
```#### Carthage
SDWebImageJPEGXLCoder is available through [Carthage](https://github.com/Carthage/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](https://swift.org/package-manager).
```swift
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
```objective-c
// Add coder
SDImageJPEGXLCoder *JPEGXLCoder = [SDImageJPEGXLCoder sharedCoder];
[[SDImageCodersManager sharedManager] addCoder:JPEGXLCoder];
```+ Swift
```swift
// Add coder
let JPEGXLCoder = SDImageJPEGXLCoder.shared
SDImageCodersManager.shared.addCoder(JPEGXLCoder)
```### Loading
+ Objective-C
```objective-c
// JPEG-XL online image loading
NSURL *JPEGXLURL;
UIImageView *imageView;
[imageView sd_setImageWithURL:JPEGXLURL];
```+ Swift
```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)
### Decoding
+ Objective-C
```objective-c
// JPEGXL image decoding
NSData *JPEGXLData;
UIImage *image = [[SDImageJPEGXLCoder sharedCoder] decodedImageWithData:JPEGXLData options:nil];
```+ Swift
```swift
// JPEGXL image decoding
let JPEGXLData: Data
let image = SDImageJPEGXLCoder.shared.decodedImage(with: data, options: nil)
```### Encoding
+ Objective-c
```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
```+ Swift
```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
```### Animated JPEG-XL Encoding
+ Objective-c
```objective-c
// Animated encoding
NSMutableArray *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];
```+ Swift
```swift
// Animated encoding
var frames: [SDImageFrame] = []
for i in 0..These JPEG-XL images are from [JXL Art Gallery](https://jpegxl.info/art/)
## Author
[DreamPiggy](https://github.com/dreampiggy)
## License
SDWebImageJPEGXLCoder is available under the MIT license. See [the LICENSE file](https://github.com/SDWebImage/SDWebImageJPEGXLCoder/blob/master/LICENSE) for more info.
## Thanks
+ [libjxl](https://github.com/SDWebImage/libjxl-Xcode)