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 = {
return canvas.toDataURL('image/png');
},
toPng: function() {
return new RSVP.Promise((function(_this) {
return function(resolve, reject) {
var dataUrl, image;
dataUrl = _this.toBase64();
dataUrl = this.toBase64();
image = new Image();
image.width = _this.width();
image.height = _this.height();
image.width = this.width();
image.height = this.height();
image.src = dataUrl;
return resolve(image);
};
})(this));
return image;
},
saveAsPng: function() {
throw "Not available in the browser. Use toPng() instead.";
......
......@@ -58,9 +58,7 @@
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());
});
}
}());
......
......@@ -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
saveAsPng: (output) ->
new RSVP.Promise (resolve, reject) =>
@toPng().then (image) ->
image
@toPng()
.pack()
.pipe(fs.createWriteStream(output))
.on 'finish', resolve
{
"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": {
......
......@@ -18,7 +18,6 @@ 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.
......@@ -27,7 +26,7 @@ module.exports =
image.height = @height()
image.src = dataUrl
resolve(image)
image
saveAsPng: ->
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