Skip to content

Commit

Permalink
Add scale arg to exportPNG()
Browse files Browse the repository at this point in the history
Closes #227
Closes #203
  • Loading branch information
tjvr committed Apr 7, 2018
1 parent af07408 commit 2070c62
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.html
Expand Up @@ -296,7 +296,7 @@ <h1>
link.textContent = "Export PNG";
link.className = 'export-link';
document.body.appendChild(link);
});
}, 2);
}, 0);

try {
Expand Down
11 changes: 8 additions & 3 deletions scratch2/blocks.js
Expand Up @@ -662,16 +662,21 @@ DocumentView.prototype.exportSVG = function() {
return "data:image/svg+xml;utf8," + xml.replace(/[#]/g, encodeURIComponent)
}

DocumentView.prototype.exportPNG = function(cb) {
DocumentView.prototype.exportPNG = function(cb, scale) {
scale = scale || 1.0

var canvas = SVG.makeCanvas()
canvas.width = this.width
canvas.height = this.height
canvas.width = this.width * scale
canvas.height = this.height * scale
var context = canvas.getContext("2d")

var image = new Image()
image.src = this.exportSVG()
image.onload = function() {
context.save()
context.scale(scale, scale)
context.drawImage(image, 0, 0)
context.restore()

if (URL && URL.createObjectURL && Blob && canvas.toBlob) {
var blob = canvas.toBlob(function(blob) {
Expand Down

0 comments on commit 2070c62

Please sign in to comment.