UIImageJPEGRepresentation is great function to downgrade the image.
I am just looking for downgrade the image to 1MB.
Yes there is a loopy way that we can apply multiple check until we receive 1024KB data count.
let image = UIImage(named: "test")!
if let imageData = UIImagePNGRepresentation(image) {
let kb = imageData.count / 1024
if kb > 1024 {
let compressedData = UIImageJPEGRepresentation(image, 0.2)!
}
}
Any elegant solution please?