Skip to content

Instantly share code, notes, and snippets.

View av01d's full-sized avatar

Arjan Haverkamp av01d

View GitHub Profile
@av01d
av01d / convert-canvas-image.js
Created July 23, 2020 07:47
Javsacript: Convert canvas to image, image to canvas
function convertImageToCanvas(image) {
var canvas = document.createElement("canvas");
canvas.width = image.width;
canvas.height = image.height;
canvas.getContext("2d").drawImage(image, 0, 0);
return canvas;
}
function convertCanvasToImage(canvas) {
var image = new Image();
@av01d
av01d / file2bitmap.js
Created July 23, 2020 07:46
File to Bitmap (on canvas)
/* HTML:
<input type="file" id="filepicker">
<canvas id="outCanvas"></canvas>
*/
filepicker.addEventListener("change", () => {
createImageBitmap(filepicker.files[0])
.then(response => {
outCanvas.width = response.width;
outCanvas.height = response.height;