Skip to content

Instantly share code, notes, and snippets.

View binhwpo's full-sized avatar

Binh Nguyen binhwpo

View GitHub Profile
@binhwpo
binhwpo / gist:dc698e982894a74a225f621d5467503b
Created March 10, 2017 17:42
Swift resizeImage function
func resizeImage(image: UIImage, newSize: CGSize) -> UIImage {
let imageSize = image.size
let width = imageSize.width
let height = imageSize.height
let widthFactor = newSize.width/width
let heightFactor = newSize.height/height
let scaledFactor = (widthFactor < heightFactor) ? widthFactor : heightFactor
let scaledWidth = width * scaledFactor