diff --git a/example/resize-svg.js b/example/resize-svg.js new file mode 100644 index 00000000..3ad3c70a --- /dev/null +++ b/example/resize-svg.js @@ -0,0 +1,30 @@ +const { promises } = require('fs') +const { join } = require('path') + +const { createCanvas, Image } = require('../index') + +async function main() { + const file = await promises.readFile(join(__dirname, './resize-svg.svg')) + + const image = new Image() + image.src = file + + const w = 500 + const h = 500 + + // resize SVG + image.width = w + image.height = h + + // create a canvas of the same size as the image + const canvas = createCanvas(w, h) + const ctx = canvas.getContext('2d') + + // fill the canvas with the image + ctx.drawImage(image, 0, 0) + + const output = await canvas.encode('png') + await promises.writeFile(join(__dirname, 'resize-svg.png'), output) +} + +main() diff --git a/example/resize-svg.png b/example/resize-svg.png new file mode 100644 index 00000000..50153107 Binary files /dev/null and b/example/resize-svg.png differ diff --git a/example/resize-svg.svg b/example/resize-svg.svg new file mode 100644 index 00000000..da715aad --- /dev/null +++ b/example/resize-svg.svg @@ -0,0 +1,9 @@ + + + + + + + + +