mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
17 lines
647 B
Swift
17 lines
647 B
Swift
|
|
extension UIImage {
|
|
|
|
func scaled(to size: CGSize) -> UIImage {
|
|
var rect = CGRect.zero
|
|
let aspectRatio = min(size.width / self.size.width, size.height / self.size.height)
|
|
rect.size.width = self.size.width * aspectRatio
|
|
rect.size.height = self.size.height * aspectRatio
|
|
rect.origin.x = (size.width - rect.size.width) / 2
|
|
rect.origin.y = (size.height - rect.size.height) / 2
|
|
UIGraphicsBeginImageContextWithOptions(size, false, 0)
|
|
draw(in: rect)
|
|
let result = UIGraphicsGetImageFromCurrentImageContext()!
|
|
UIGraphicsEndImageContext()
|
|
return result
|
|
}
|
|
}
|