Skip to content

Commit

Permalink
feat: add resize SVG demo
Browse files Browse the repository at this point in the history
  • Loading branch information
yisibl committed Aug 12, 2021
1 parent d2a848d commit bf8388d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
30 changes: 30 additions & 0 deletions example/resize-svg.js
Original file line number Diff line number Diff line change
@@ -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()
Binary file added example/resize-svg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions example/resize-svg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

1 comment on commit bf8388d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: bf8388d Previous: ead9d75 Ratio
Draw house#skia-canvas 27 ops/sec (±0.09%) 20.1 ops/sec (±0.66%) 0.74
Draw house#node-canvas 23 ops/sec (±0.32%) 20.5 ops/sec (±1.29%) 0.89
Draw house#@napi-rs/skia 24 ops/sec (±0.43%) 21.5 ops/sec (±0.94%) 0.90
Draw gradient#skia-canvas 26 ops/sec (±0.12%) 19.1 ops/sec (±1.47%) 0.73
Draw gradient#node-canvas 22 ops/sec (±0.28%) 19.7 ops/sec (±1.28%) 0.90
Draw gradient#@napi-rs/skia 24 ops/sec (±0.12%) 20.4 ops/sec (±0.62%) 0.85

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.