Skip to content

Instantly share code, notes, and snippets.

View AdamLantz's full-sized avatar
🎉
Having a blast!

Adam Lantz AdamLantz

🎉
Having a blast!
View GitHub Profile
@AdamLantz
AdamLantz / UIImage+Cropping.swift
Created June 20, 2018 16:03
Swift 4 - Crop transparent pixels from UIImage
//Swift 4 modifications for this gist: https://gist.github.com/krooked/9c4c81557fc85bc61e51c0b4f3301e6e
import Foundation
import UIKit
extension UIImage {
func cropImageByAlpha() -> UIImage {
let cgImage = self.cgImage
let context = createARGBBitmapContextFromImage(inImage: cgImage!)
let height = cgImage!.height
let width = cgImage!.width