 extension UIImage {
     /// Creates and returns a copy of the receiver image by changing the color space to gray.
     public var grayed: UIImage! {
-        guard let cgImage = self.cgImage else { return nil }
+        guard let cgImage = self._makeCgImage() else { return nil }
         let colorSpace = CGColorSpaceCreateDeviceGray()
         guard let context = CGContext(data: nil, width: cgImage.width, height: cgImage.height, bitsPerComponent: 8, bytesPerRow: 0, space: colorSpace, bitmapInfo: CGImageAlphaInfo.none.rawValue) else { return nil }
         

            
            return UIImage(cgImage: cgImage, scale: scale, orientation: imageOrientation)
        default:
            guard let cgImage = self.cgImage?.cropping(to: croppingRect) else { return nil }
            return UIImage(cgImage: cgImage, scale: scale, orientation: imageOrientation)
        }
    }

    public func tint(with color: UIColor) -> UIImage! {
        UIGraphicsBeginImageContextWithOptions(size, false, scale)
        defer { UIGraphicsEndImageContext() }
        guard let cgImage = self._makeCgImage(), let context = UIGraphicsGetCurrentContext() else { return nil }
        context.translateBy(x: 0.0, y: scaledHeight)
        context.scaleBy(x: 1.0, y: -1.0)
        context.setBlendMode(.normal)
