I want to reduce the size of image like this website http://resizeimage.net my image is 1080 x 360 size 120kb after I used the code below but when I use the website I get 58kb or if there is a library or algorithm to compress JPEG file
func resizeImage(_ image: UIImage, newHeight: CGFloat) -> UIImage {
let scale = newHeight / image.size.height
let newWidth = image.size.width * scale
UIGraphicsBeginImageContext(CGSize(width: newWidth, height: newHeight))
image.draw(in: CGRect(x: 0, y: 0, width: newWidth, height: newHeight))
let newImage = UIGraphicsGetImageFromCurrentImageContext()
let imageData = UIImageJPEGRepresentation(newImage!, 0.5)! as Data
UIGraphicsEndImageContext()
return UIImage(data:imageData)!
}