Skip to content

Instantly share code, notes, and snippets.

@francoismarceau29
Created September 11, 2017 22:49
Show Gist options
  • Save francoismarceau29/9d0f61be390c0364dc36d41c5e088458 to your computer and use it in GitHub Desktop.
Save francoismarceau29/9d0f61be390c0364dc36d41c5e088458 to your computer and use it in GitHub Desktop.
Resizing a UIImage
func resize(image: UIImage, newSize: CGSize) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0)
image.draw(in: CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height))
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment