create canvas 10x165mm black in javascript

You can create a canvas element programmatically using JavaScript and then apply its attributes as per your requirements. Here's the code to create a black canvas with dimensions 10x165mm:

index.tsx
// Create a canvas element
const canvas = document.createElement('canvas');

// Define the canvas width and height in pixels
canvas.width = 377.95; // This converts 10mm into pixels assuming 96dpi
canvas.height = 58.27; // This converts 165mm into pixels assuming 96dpi

// Get the canvas context and set it to 2d
const context = canvas.getContext('2d');

// Apply black color to the canvas
context.fillStyle = 'black';
context.fillRect(0, 0, canvas.width, canvas.height);

// Add the canvas element to the DOM
document.body.appendChild(canvas);
546 chars
17 lines

Note that the size of the canvas might not be exactly 10x165mm due to varying screen densities.

related categories

gistlibby LogSnag