From b56085b649b208234ec704d0cff0fb231fe31cfb Mon Sep 17 00:00:00 2001 From: Ryan LeFevre Date: Wed, 25 Feb 2015 19:02:16 -0500 Subject: [PATCH] Fix toPng so that it's no longer asynchronous #19 --- dist/psd.js | 18 +++++++----------- examples/browser/image.html | 6 ++---- lib/psd/image_exports/png.coffee | 17 +++++++---------- package.json | 2 +- shims/png.coffee | 19 +++++++++---------- 5 files changed, 26 insertions(+), 36 deletions(-) diff --git a/dist/psd.js b/dist/psd.js index 7e992b3..02f47c6 100644 --- a/dist/psd.js +++ b/dist/psd.js @@ -16778,17 +16778,13 @@ module.exports = { return canvas.toDataURL('image/png'); }, toPng: function() { - return new RSVP.Promise((function(_this) { - return function(resolve, reject) { - var dataUrl, image; - dataUrl = _this.toBase64(); - image = new Image(); - image.width = _this.width(); - image.height = _this.height(); - image.src = dataUrl; - return resolve(image); - }; - })(this)); + var dataUrl, image; + dataUrl = this.toBase64(); + image = new Image(); + image.width = this.width(); + image.height = this.height(); + image.src = dataUrl; + return image; }, saveAsPng: function() { throw "Not available in the browser. Use toPng() instead."; diff --git a/examples/browser/image.html b/examples/browser/image.html index fbd21e8..8491858 100644 --- a/examples/browser/image.html +++ b/examples/browser/image.html @@ -58,12 +58,10 @@ PSD.fromEvent(e).then(function (psd) { var data = JSON.stringify(psd.tree().export(), undefined, 2); document.getElementById('data').innerHTML = data; - psd.image.toPng().then(function (image) { - document.getElementById('image').appendChild(image); - }); + document.getElementById('image').appendChild(psd.image.toPng()); }); } }()); - \ No newline at end of file + diff --git a/lib/psd/image_exports/png.coffee b/lib/psd/image_exports/png.coffee index 5df7f26..a08bf06 100644 --- a/lib/psd/image_exports/png.coffee +++ b/lib/psd/image_exports/png.coffee @@ -4,16 +4,13 @@ RSVP = require 'rsvp' module.exports = toPng: -> - new RSVP.Promise (resolve, reject) => - png = new PNG(filterType: 4, width: @width(), height: @height()) - - png.data = @pixelData - resolve(png) + png = new PNG(filterType: 4, width: @width(), height: @height()) + png.data = @pixelData + png saveAsPng: (output) -> new RSVP.Promise (resolve, reject) => - @toPng().then (image) -> - image - .pack() - .pipe(fs.createWriteStream(output)) - .on 'finish', resolve + @toPng() + .pack() + .pipe(fs.createWriteStream(output)) + .on 'finish', resolve diff --git a/package.json b/package.json index 506f203..c319ba9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "psd", "description": "A general purpose Photoshop file parser.", - "version": "1.1.0", + "version": "2.0.0", "main": "./index.js", "keywords": ["psd", "parser", "photoshop", "adobe", "reader"], "repository": { diff --git a/shims/png.coffee b/shims/png.coffee index 7ff56c0..4efe9a3 100644 --- a/shims/png.coffee +++ b/shims/png.coffee @@ -18,16 +18,15 @@ module.exports = canvas.toDataURL 'image/png' toPng: -> - new RSVP.Promise (resolve, reject) => - dataUrl = @toBase64() - # Create the image and set the source to the - # canvas data URL. - image = new Image() - image.width = @width() - image.height = @height() - image.src = dataUrl + dataUrl = @toBase64() + # Create the image and set the source to the + # canvas data URL. + image = new Image() + image.width = @width() + image.height = @height() + image.src = dataUrl - resolve(image) + image saveAsPng: -> - throw "Not available in the browser. Use toPng() instead." \ No newline at end of file + throw "Not available in the browser. Use toPng() instead."