Skip to content

Instantly share code, notes, and snippets.

@asraful
Last active October 12, 2020 08:07
Show Gist options
  • Save asraful/6cb2b46019671dc946a43c28979f91c7 to your computer and use it in GitHub Desktop.
Save asraful/6cb2b46019671dc946a43c28979f91c7 to your computer and use it in GitHub Desktop.
app.get('/demo', (req, res) => {
const { createCanvas, loadImage } = require('canvas')
var sizeOf = require('image-size');
var dimensions = sizeOf('sample.jpg');
const width = dimensions.width;
const height = dimensions.height;
const canvas = createCanvas(width, height)
const ctx = canvas.getContext('2d')
loadImage('landmark.jpg').then((image) => {
//draw same original image
ctx.drawImage(image, 0, 0)
// Red rectangle
ctx.beginPath();
ctx.lineWidth = "4";
ctx.strokeStyle = "red";
//change the data as required
ctx.rect(125,251,419,317)
//manual line draw , //change the data as required
//ctx.moveTo(226,126);
//ctx.lineTo(561,125);
//ctx.lineTo(561,521);
//ctx.lineTo(226,521);
//ctx.lineTo(226,126);
ctx.stroke();
res.status(200).send(canvas.toDataURL('jpg,0.4'));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment