Skip to content

Instantly share code, notes, and snippets.

@vlondon
vlondon / ImageToGrayscale.swift
Last active October 22, 2021 12:15
Convert image to grayscale
func convertImageToGrayScale(image: UIImage) -> UIImage {
// Create image rectangle with current image width/height
let imageRect: CGRect = CGRectMake(0, 0, image.size.width, image.size.height)
// Grayscale color space
let colorSpace: CGColorSpaceRef = CGColorSpaceCreateDeviceGray()
// Create bitmap content with current image size and grayscale colorspace
let bitmapInfo = CGBitmapInfo(CGImageAlphaInfo.None.rawValue)
var context = CGBitmapContextCreate(nil, UInt(image.size.width), UInt(image.size.height), 8, 0, colorSpace, bitmapInfo)
@InfernoZeus
InfernoZeus / html2canvas-indexsizeerror-patch.diff
Last active November 3, 2017 06:53
Patches for html2canvas to fix: - jump back to previous scroll position after parsing - indexsizeerror dom exception when element being rendered had size 0
diff --git a/content/scripts/html2canvas.js b/content/scripts/html2canvas.js
index 7ab27ed..52f3eab 100644
--- a/content/scripts/html2canvas.js
+++ b/content/scripts/html2canvas.js
@@ -2830,9 +2830,10 @@ _html2canvas.Renderer.Canvas = function(options) {
newCanvas = doc.createElement('canvas');
newCanvas.width = bounds.width;
newCanvas.height = bounds.height;
- ctx = newCanvas.getContext("2d");
-