If anyone is looking for swift-3 version
self.postImage.sd_setImage(with: URL(string: image)!, placeholderImage: UIImage(named: "image_placeholder"),options: SDWebImageOptions(rawValue: 0),
completed: { (image, error, cacheType, imageURL) in
//Scale or do what ever you want to do to the image
let newImage = self.scaleImage(image: image!, view: self.postImage)
self.postImage.image = newImage
})
func scaleImage(image:UIImage, view:UIImageView) -> UIImage {
let oldWidth = image.size.width
let oldHeight = image.size.height
var scaleFactor:CGFloat
var newHeight:CGFloat
var newWidth:CGFloat
let viewWidth:CGFloat = view.width
if oldWidth > oldHeight {
scaleFactor = oldHeight/oldWidth
newHeight = viewWidth * scaleFactor
newWidth = viewWidth
} else {
scaleFactor = oldHeight/oldWidth
newHeight = viewWidth * scaleFactor
newWidth = viewWidth
}
UIGraphicsBeginImageContext(CGSize(width:newWidth, height:newHeight))
image.draw(in: CGRect(x:0, y:0, width:newWidth, height:newHeight))
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage!
}
`