         generatedImage = nil
     }
 
-    func image() -> CGImage {
+    func image() -> CGImage? {
         if let image = generatedImage {
             return image
         }

        let h = Int(size.height * scale)
        let bitsPerComponent: Int = MemoryLayout<UInt8>.size * 8
        let bytesPerPixel: Int = bitsPerComponent * 4 / 8

        var data = [ARGB]()

        for y in 0..<h {

                data.append(c)
            }
        }
        
        // Fix for #63 - force retain `data` to prevent crash when CGContext uses the buffer
        let image: CGImage? = withExtendedLifetime(&data) { (data: UnsafeMutableRawPointer) -> CGImage? in
            guard let ctx = CGContext(
                data: data,
                width: w,
                height: h,
                bitsPerComponent: bitsPerComponent,
                bytesPerRow: w * bytesPerPixel,
                space: colorSpace,
                bitmapInfo: bitmapInfo.rawValue
            ) else {
                return nil
            }
            ctx.interpolationQuality = .none
            ctx.setShouldAntialias(false)
            
            return ctx.makeImage()
        }
        
        generatedImage = image
        return image
    }

    private func pixelDataForGradient(at point: CGPoint,
