Closed recherst closed 5 years ago
I just tried it out myself and it worked without any problem. Would you mind telling me which version of KingfisherWebP and iOS you are using?
@Yeatse the version of KingfisherWebP is 0.5.0 (latest) and iOS deploying target is iOS 10 above, also Kingfisher version is 5.0.0 (latest).
btw, my imageView inherits AnimatedImageView
from Kingfisher library. and in this class, i made some configurations
override init(frame: CGRect) {
super.init(frame: frame)
needsPrescaling = false
runLoopMode = RunLoop.Mode.default
}
would these two options influence your library to decode webp image?
and i found another problem is that if passed a RoundCornerImageProcessor
processor to options parameter, webp image can not display on imageview, like this
imgView.kf.setImage(with: URL(string: urlStr),
placeholder: somePlaceholder,
options: [.backgroundDecode, RoundCornerImageProcessor(cornerRadius: 8)])
i don't know whether it's my problem, kindly hope reply.
hi, i got new discovery!
first, there is no problem on usage, surely that's my mistakes.
and i found if you set a RoundCornerImageProcessor
processor which crops round corner for options
parameter, the webp image can not display.
otherwise, if you retrieve the image from completion handler and make some modifications like to cropping round, it can not animate if this is a animated webp image.
some code like
{ result in
guard let image = result.value?.image else { return }
imageView.image = image.kf.scaled(to: UIScreen.main.scale)
.kf.image(withRoundRadius: 8.0, fit: imageView.frame.size)
}
Thanks for your detailed information. Having looked into the implementation of RoundCornerImageProcessor, I found it cannot handle animated or webp images very well:
// implementation of RoundCornerImageProcessor:
public func process(item: ImageProcessItem, options: KingfisherParsedOptionsInfo) -> Image? {
switch item {
case .image(let image):
let size = targetSize ?? image.kf.size
return image.kf.scaled(to: options.scaleFactor)
.kf.image(
withRoundRadius: cornerRadius,
fit: size,
roundingCorners: roundingCorners,
backgroundColor: backgroundColor)
case .data:
return (DefaultImageProcessor.default >> self).process(item: item, options: options)
}
}
// implementation of image.kf.scaled:
public func scaled(to scale: CGFloat) -> Image {
guard scale != self.scale else {
return base
}
guard let cgImage = cgImage else {
assertionFailure("[Kingfisher] Scaling only works for CG-based image.")
return base
}
return KingfisherWrapper.image(cgImage: cgImage, scale: scale, refImage: base)
}
RoundCornerImageProcessor just takes cgImage
property from input images, ignoring the animated frames in images
property, whether it's webp or not.
What's more, if the processor receives raw image data, it will firstly covert it to image with DefaultImageProcessor
, ignoring any other processor specified in defaultOptions
.
So if you want round cornered & animated images from Kingfisher, you would better leave your original image unprocessed and crop the containing image views, despite the performance degradation :/
thank you very much! i'm considering whether crop the imageview. as you saying it take some cost on performance, especially on a plenty of images list. thanks again ~
i find an issue #13 which you had supported animated webp, i try to fetch a resource webp image from server, but it didn't work, i don't know whether my usage is wrong? i paste some code in here.
then , in somewhere
need some other configurations?
give a resource for test
https://p.upyun.com/demo/webp/webp/animated-gif-0.webp
thanks