New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AVIF Support #2189
Comments
Our project currently heavily uses Kingfisher, but we struggle loading images in AVIF format. |
Hi, As I tried, it seems that the default image processor is already supporting AVIF with UIImageView extension, so I guess you can just give the URL of an AVIF image to Kingfisher and it should just work. See the example in action: As I tried under iOS 16 and iOS 17, both seems working fine. Do you have a case (maybe any earlier iOS versions?) that it does not work? If the default one does not work in some cases, it is still very easy to integrating any existing AVIF decoder to Kingfisher. Take the avif.swift as example, after importing, you can add these to your project to load an AVIF image: struct KingfisherAVIFProcessor: ImageProcessor {
var identifier: String = "KingfisherAVIF"
func process(item: ImageProcessItem, options: KingfisherParsedOptionsInfo) -> KFCrossPlatformImage? {
switch item {
case .data(let data):
return AVIFDecoder.decode(data)
case .image(let image):
return image
}
}
}
struct KingfisherAVIFSerializer: CacheSerializer {
func data(with image: Kingfisher.KFCrossPlatformImage, original: Data?) -> Data? {
return try? AVIFEncoder.encode(image: image, quality: 50)
}
func image(with data: Data, options: Kingfisher.KingfisherParsedOptionsInfo) -> Kingfisher.KFCrossPlatformImage? {
return AVIFDecoder.decode(data)
}
} And use it as: imageView.kf.setImage(
with: url,
options: [
.processor(KingfisherAVIFProcessor()),
.cacheSerializer(KingfisherAVIFSerializer())
]
) |
hey @onevcat , thanks for the quick reply! You're right, it works fine in most cases. I forgot to mention, that it doesn't works on iOS 15. I've checked on iPhone 13 mini, iOS 15.4. |
For that case, maybe I can recommend to apply the struct KingfisherAVIFProcessor: ImageProcessor {
var identifier: String = "KingfisherAVIF"
func process(item: ImageProcessItem, options: KingfisherParsedOptionsInfo) -> KFCrossPlatformImage? {
switch item {
case .data(let data):
return DefaultImageProcessor.default.process(item: item, options: options) ?? AVIFDecoder.decode(data)
case .image(let image):
return image
}
}
} Then it is possible for you to get the system default implementation if the system can decode the image. Otherwise if for older systems, fallback to the AVIF specified decoders. |
yeah, keeping default image processor make sense. thanks for sharing thoughts! |
Any news about AVIF support?
The text was updated successfully, but these errors were encountered: