Created
February 24, 2016 23:11
-
-
Save brbcoding/e76446b13daf1b28230b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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