Skip to content

Instantly share code, notes, and snippets.

@brbcoding
Created February 24, 2016 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brbcoding/e76446b13daf1b28230b to your computer and use it in GitHub Desktop.
Save brbcoding/e76446b13daf1b28230b to your computer and use it in GitHub Desktop.
//
// Extensions.swift
// Commerzbank
//
// Created by Cody Henshaw on 2/24/16.
// Copyright © 2016 Cody Henshaw. All rights reserved.
//
import Foundation
import UIKit
extension UIImage {
func scaleToWidth(originalImage: UIImage, toWidth: CGFloat) -> UIImage {
let height = originalImage.size.height * (toWidth / originalImage.size.width)
let size = CGSizeMake(toWidth, height)
UIGraphicsBeginImageContext(size)
originalImage.drawInRect(CGRectMake(0.0, 0.0, size.width, size.height))
let scaledImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return scaledImage
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment