Public
Edited
Aug 29, 2023
1 fork
Importers
29 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
getImageData = async function (blob) {
const bitmap = await createImageBitmap(blob);
const { width, height } = bitmap;

// an intermediate "buffer" 2D context is necessary
const ctx = DOM.context2d(width, height, 1);
ctx.drawImage(bitmap, 0, 0);

return ctx.getImageData(0, 0, width, height);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
image2canvas = (imageData, width) => {
const context = DOM.context2d(imageData.width, imageData.height, 1);
context.putImageData(imageData, 0, 0);
if (!width || imageData.width <= width) return context.canvas;

const height = (imageData.height * width) / imageData.width;
const contextr = DOM.context2d(width, height, 1);
contextr.drawImage(context.canvas, 0, 0, width, height);
return contextr.canvas;
}
Insert cell
//import { image2canvas } from "@ehouais/utils"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more