UPDATE LIST
- Fix the issue where part of the memory remains during image compression.
- Removed the
resizeImage(_ image, maxDimension:) function.
- Image resizing is now performed internally using a new
downSample(_ image, maxDimension:) method for improved memory efficiency during compression.
- The
downSample method is currently internal and not yet public.
- It will be revealed in the next update so that developers can make more control over the downsampling behavior.
@available(*, message: "This Function Will Be Deprecated Soon Use downsampling function")
public func resizeImage(_ image: UIImage, maxDimension: CGFloat) -> UIImage {
let width = image.size.width
let height = image.size.height
guard width > maxDimension || height > maxDimension else {
return image
}
let aspectRatio: CGFloat = width / height
var newSize: CGSize
// Vertical
if aspectRatio > 1 {
newSize = CGSize(width: maxDimension, height: maxDimension / aspectRatio)
}
// Horizontal
else {
newSize = CGSize(width: maxDimension * aspectRatio, height: maxDimension)
}
let renderer = UIGraphicsImageRenderer(size: newSize)
return renderer.image { context in
image.draw(in: CGRect(origin: .zero, size: newSize))
}
}