             imageSize.height += self.borderWidth * 2
         }
 
-        let image = UIImage(size: imageSize) { context in
+        var image = UIImage.with(size: imageSize) { context in
             self.color.setFill()
             self.borderColor.setStroke()
 

            path.lineWidth = self.borderWidth
            path.fill()
            path.stroke()
        }!

        if useCache {
            self.dynamicType.cachedImages[self.cacheKey] = image


public extension UIImage {

    public typealias ContextBlock = (CGContextRef) -> Void

    public class func with(#width: CGFloat, height: CGFloat, block: ContextBlock) -> UIImage {
        return self.with(size: CGSize(width: width, height: height), block: block)
    }

    public class func with(#size: CGSize, opaque: Bool = false, scale: CGFloat = 0, block: ContextBlock) -> UIImage {
        UIGraphicsBeginImageContextWithOptions(size, opaque, scale)
        let context = UIGraphicsGetCurrentContext()
        block(context)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image
    }

    public func with(contextBlock: (CGContextRef) -> Void) -> UIImage! {
        return UIImage.with(size: self.size, opaque: false, scale: self.scale) { context in
            let rect = CGRect(x: 0, y: 0, width: self.size.width, height: self.size.height)
            CGContextDrawImage(context, rect, self.CGImage)
            contextBlock(context)
