Commit b56085b6 authored by Ryan LeFevre's avatar Ryan LeFevre

Fix toPng so that it's no longer asynchronous #19

parent 243439e9
...@@ -16778,17 +16778,13 @@ module.exports = { ...@@ -16778,17 +16778,13 @@ module.exports = {
return canvas.toDataURL('image/png'); return canvas.toDataURL('image/png');
}, },
toPng: function() { toPng: function() {
return new RSVP.Promise((function(_this) {
return function(resolve, reject) {
var dataUrl, image; var dataUrl, image;
dataUrl = _this.toBase64(); dataUrl = this.toBase64();
image = new Image(); image = new Image();
image.width = _this.width(); image.width = this.width();
image.height = _this.height(); image.height = this.height();
image.src = dataUrl; image.src = dataUrl;
return resolve(image); return image;
};
})(this));
}, },
saveAsPng: function() { saveAsPng: function() {
throw "Not available in the browser. Use toPng() instead."; throw "Not available in the browser. Use toPng() instead.";
......
...@@ -58,9 +58,7 @@ ...@@ -58,9 +58,7 @@
PSD.fromEvent(e).then(function (psd) { PSD.fromEvent(e).then(function (psd) {
var data = JSON.stringify(psd.tree().export(), undefined, 2); var data = JSON.stringify(psd.tree().export(), undefined, 2);
document.getElementById('data').innerHTML = data; document.getElementById('data').innerHTML = data;
psd.image.toPng().then(function (image) { document.getElementById('image').appendChild(psd.image.toPng());
document.getElementById('image').appendChild(image);
});
}); });
} }
}()); }());
......
...@@ -4,16 +4,13 @@ RSVP = require 'rsvp' ...@@ -4,16 +4,13 @@ RSVP = require 'rsvp'
module.exports = module.exports =
toPng: -> toPng: ->
new RSVP.Promise (resolve, reject) =>
png = new PNG(filterType: 4, width: @width(), height: @height()) png = new PNG(filterType: 4, width: @width(), height: @height())
png.data = @pixelData png.data = @pixelData
resolve(png) png
saveAsPng: (output) -> saveAsPng: (output) ->
new RSVP.Promise (resolve, reject) => new RSVP.Promise (resolve, reject) =>
@toPng().then (image) -> @toPng()
image
.pack() .pack()
.pipe(fs.createWriteStream(output)) .pipe(fs.createWriteStream(output))
.on 'finish', resolve .on 'finish', resolve
{ {
"name": "psd", "name": "psd",
"description": "A general purpose Photoshop file parser.", "description": "A general purpose Photoshop file parser.",
"version": "1.1.0", "version": "2.0.0",
"main": "./index.js", "main": "./index.js",
"keywords": ["psd", "parser", "photoshop", "adobe", "reader"], "keywords": ["psd", "parser", "photoshop", "adobe", "reader"],
"repository": { "repository": {
......
...@@ -18,7 +18,6 @@ module.exports = ...@@ -18,7 +18,6 @@ module.exports =
canvas.toDataURL 'image/png' canvas.toDataURL 'image/png'
toPng: -> toPng: ->
new RSVP.Promise (resolve, reject) =>
dataUrl = @toBase64() dataUrl = @toBase64()
# Create the image and set the source to the # Create the image and set the source to the
# canvas data URL. # canvas data URL.
...@@ -27,7 +26,7 @@ module.exports = ...@@ -27,7 +26,7 @@ module.exports =
image.height = @height() image.height = @height()
image.src = dataUrl image.src = dataUrl
resolve(image) image
saveAsPng: -> saveAsPng: ->
throw "Not available in the browser. Use toPng() instead." throw "Not available in the browser. Use toPng() instead."
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment