Skip to content

Commit

Permalink
Merge pull request #153 from louh/louh/device-pixel-ratio
Browse files Browse the repository at this point in the history
feat(png): saved image uses device pixel ratio
  • Loading branch information
cy6erskunk authored May 20, 2020
2 parents 9ebb6d8 + 5b29a49 commit 30b1d34
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/png.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import {DEFAULT_FILENAME} from './const'

function downloadPng(source, filename = DEFAULT_FILENAME) {
const canvas = document.createElement('canvas')
const dpr = window.devicePixelRatio || 1
document.body.appendChild(canvas)
canvas.setAttribute('id', 'svg-image')
canvas.setAttribute('width', source.width)
canvas.setAttribute('height', source.height)
canvas.setAttribute('width', source.width * dpr)
canvas.setAttribute('height', source.height * dpr)
canvas.style.display = 'none'

const context = canvas.getContext('2d')
Expand All @@ -15,6 +16,7 @@ function downloadPng(source, filename = DEFAULT_FILENAME) {
const image = new Image()

function onLoad() {
context.scale(dpr, dpr)
context.drawImage(image, 0, 0)
const canvasdata = canvas.toDataURL('image/png')

Expand Down

0 comments on commit 30b1d34

Please sign in to comment.