16 lines
512 B
Swift
16 lines
512 B
Swift
import CoreGraphics
|
|
|
|
enum ImageCropGeometry {
|
|
static func maximumCropSize(fitting imageSize: CGSize, aspectRatio: CGFloat) -> CGSize {
|
|
guard imageSize.width > 0, imageSize.height > 0, aspectRatio > 0 else {
|
|
return .zero
|
|
}
|
|
|
|
if imageSize.width / imageSize.height > aspectRatio {
|
|
return CGSize(width: imageSize.height * aspectRatio, height: imageSize.height)
|
|
}
|
|
|
|
return CGSize(width: imageSize.width, height: imageSize.width / aspectRatio)
|
|
}
|
|
}
|