In my project I was using AlamofireImage in swift. Now we replaced AlamofireImage with the KingFisher library. I have created a struct using below to fit the filter
struct AspectScaledToFitAndCenterSizeFilter: ImageFilter, Sizable {
/// The size of the filter.
let size: CGSize
/// Initializes the `AspectScaledToFitSizeFilter` instance with the given size.
///
/// - parameter size: The size.
///
/// - returns: The new `AspectScaledToFitSizeFilter` instance.
init(size: CGSize) {
self.size = size
}
/// The filter closure used to create the modified representation of the given image.
var filter: (UIImage) -> UIImage {
{ image in
image.imageAspectScaledAndCenter(toFit: self.size)
}
}
}
When we are using AlmofireImage using the below code to set image url
imageView.af.setImage(withURL: imageURL.mediaURL(), placeholderImage: #imageLiteral(resourceName: "icMissingEntreeGrid"), filter: AspectScaledToFitAndCenterSizeFilter(size: imageSize))
Now I replace the code with
imageView.kf.setImage(with: imageURL.mediaURL(), placeholder: imageLiteral(resourceName: "icMissingEntreeGrid"))
But how to add that “AspectScaledToFitAndCenterSizeFilter(size: imageSize)” using KingFisher library. Could anyone please help me out here. Thanks in advance.
To create Kingfisher image processor you need to implement
ImageProcessorprotocol:Usage:
Check out more processor usages in documentation.