         
         str.drawInRect(CGRectMake(0, CGRectGetMaxY(cutout) + 14.0, rect.width, 22), withAttributes: attr)
     }
-}
+    
+    func cropImage(image: UIImage) -> UIImage? {
+        guard let cgimg = image.CGImage else {
+            return nil
+        }
+        let rect = CGRectMake(0, 0, image.size.width, image.size.height)
+        let width = rect.size.width * 0.9
+        var cutout = CGRect(origin: rect.origin,
+                            size: CGSize(width: width, height: width * 0.65))
+        cutout.origin.x = (rect.size.width - cutout.size.width) * 0.5
+        cutout.origin.y = (rect.size.height - cutout.size.height) * 0.5
+        cutout = CGRectIntegral(cutout)
+        
+        func rad(f: CGFloat) -> CGFloat {
+            return f / 180.0 * CGFloat(M_PI)
+        }
+        
+        var transform: CGAffineTransform!
+        switch image.imageOrientation {
+        case .Left:
+            transform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(rad(90)), 0, -image.size.height)
+        case .Right:
+            transform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(rad(-90)), -image.size.width, 0)
+        case .Down:
+            transform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(rad(-180)), -image.size.width, -image.size.height)
+        default:
+            transform = CGAffineTransformIdentity
+        }
+        transform = CGAffineTransformScale(transform, image.scale, image.scale)
+        cutout = CGRectApplyAffineTransform(cutout, transform)
+        
+        print("img \(image.size)")
+        print("cutout x=\(cutout.origin.x) y=\(cutout.origin.y) w=\(cutout.size.width) h=\(cutout.size.height))")
+        guard let retRef = CGImageCreateWithImageInRect(cgimg, cutout) else {
+            return nil
+        }
+        return UIImage(CGImage: retRef, scale: image.scale, orientation: image.imageOrientation)
+    }
+}

                self.response = nil
            }
            do {
                let id = try self.writeImage(img)
                print(["[BRCameraPlugin] wrote image to \(id)"])
                let respData = [

        guard let resp = self.response else {
            return
        }
        guard var img = info[UIImagePickerControllerOriginalImage] as? UIImage else {
            print("[BRCameraPlugin] error picking image... original image doesnt exist. data: \(info)")
            resp.provide(500)
            response = nil
