Skip to content

Instantly share code, notes, and snippets.

@ErnestoRB
Created January 2, 2023 01:55
Show Gist options
  • Save ErnestoRB/8df05c177d0fde72c3cf6b70fbbc791f to your computer and use it in GitHub Desktop.
Save ErnestoRB/8df05c177d0fde72c3cf6b70fbbc791f to your computer and use it in GitHub Desktop.
Draw image to specified width (node-canvas)
function draw(ctx, x,y, image, width, height){
ctx.save()
ctx.translate(x, y)
ctx.scale(width / image.width, height / image.height)
ctx.drawImage(image, 0, 0)
ctx.restore()
}
@ErnestoRB
Copy link
Author

Gist based on @rhengles solution Automattic/node-canvas#1271

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment