Hello I am displaying images on my app using sdwebImage
. I have a code here to resize the image
func resizeImage(image: UIImage, newWidth: CGFloat) -> UIImage {
let scale = newWidth / image.size.width
let newHeight = image.size.height * scale
UIGraphicsBeginImageContext(CGSizeMake(newWidth, newHeight))
image.drawInRect(CGRectMake(0, 0, newWidth, newHeight))
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage
}
The problem is the above function accepts the UIImage as parameter and sdwebimage
accepts the URL. How can I call the above resize function in sdwebimage. or in short how Can I resize the image that are presenting through sdwebImage here
cell.profileImageView.sd_setImageWithURL(UIImage().absoluteURL(profileImageUrl as! String), placeholderImage: UIImage.init(named: "default-profile-icon")?.circle!, completed: completionBlock)
do like
cell.profileImageView.sd_setImageWithURL(
NSURL(string: profileImageUrl as! String),
placeholderImage: UIImage.init(named: "default-profile-icon"),
options: nil,
progress: nil,
completed: { (image: UIImage?, error: NSError?, cacheType: SDImageCacheType!, imageURL: NSURL?) in
guard let image = image else { return }
print("Image arrived!")
cell.profileImageView.image = resizeImage(image, newWidth: 200)
}
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With