2023-03-11 18:30:33 +01:00
|
|
|
//
|
|
|
|
// https://mczachurski.dev
|
|
|
|
// Copyright © 2023 Marcin Czachurski and the repository contributors.
|
|
|
|
// Licensed under the MIT License.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
extension UIImage {
|
|
|
|
func resized(toWidth width: CGFloat, isOpaque: Bool = true) -> UIImage? {
|
|
|
|
let canvas = CGSize(width: width, height: CGFloat(ceil(width/size.width * size.height)))
|
|
|
|
|
|
|
|
let format = imageRendererFormat
|
|
|
|
format.opaque = isOpaque
|
|
|
|
|
|
|
|
return UIGraphicsImageRenderer(size: canvas, format: format).image {
|
|
|
|
_ in draw(in: CGRect(origin: .zero, size: canvas))
|
|
|
|
}
|
|
|
|
}
|
2023-03-11 18:53:58 +01:00
|
|
|
|
|
|
|
func resized(toHeight height: CGFloat, isOpaque: Bool = true) -> UIImage? {
|
|
|
|
let canvas = CGSize(width: CGFloat(ceil(height/size.height * size.width)), height: height)
|
|
|
|
|
|
|
|
let format = imageRendererFormat
|
|
|
|
format.opaque = isOpaque
|
|
|
|
|
|
|
|
return UIGraphicsImageRenderer(size: canvas, format: format).image {
|
|
|
|
_ in draw(in: CGRect(origin: .zero, size: canvas))
|
|
|
|
}
|
|
|
|
}
|
2023-03-11 18:30:33 +01:00
|
|
|
}
|