Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jacobsapps/eea671cb6ea786c4ae2278e31bb80d8d to your computer and use it in GitHub Desktop.

Select an option

Save jacobsapps/eea671cb6ea786c4ae2278e31bb80d8d to your computer and use it in GitHub Desktop.
extension UIImage {
func resized(to width: CGFloat) -> UIImage {
let ratio = size.height / size.width
let size = CGSize(width: width, height: width * ratio)
let renderer = UIGraphicsImageRenderer(size: size)
return renderer.image { _ in
self.draw(in: CGRect(origin: .zero, size: size))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment