Commit 67a3772c authored by Ryan LeFevre's avatar Ryan LeFevre

First working example

parent f92d255c
...@@ -4,10 +4,14 @@ var file = process.argv[2] || './examples/images/example.psd'; ...@@ -4,10 +4,14 @@ var file = process.argv[2] || './examples/images/example.psd';
var start = new Date(); var start = new Date();
PSD.open(file).then(function (psd) { PSD.open(file).then(function (psd) {
return psd.tree().descendants().forEach(function (node) { psd.tree().descendants().forEach(function (node) {
if (node.isGroup()) return true; if (node.isGroup()) return true;
return node.layer.image.saveAsPng("./output/#{node.name}.png"); node.layer.image.saveAsPng("./output/" + node.name + ".png").catch(function (err) {
console.log(err.stack);
});
}); });
}).then(function () { }).then(function () {
console.log("Finished in " + ((new Date()) - start) + "ms"); console.log("Finished in " + ((new Date()) - start) + "ms");
});; }).catch(function (err) {
console.log(err.stack);
});
...@@ -7,6 +7,9 @@ module.exports = class ChannelImage extends Image ...@@ -7,6 +7,9 @@ module.exports = class ChannelImage extends Image
@includes ImageFormat.LayerRLE @includes ImageFormat.LayerRLE
constructor: (file, header, @layer) -> constructor: (file, header, @layer) ->
@_width = @layer.width
@_height = @layer.height
super(file, header) super(file, header)
@channelsInfo = @layer.channelsInfo @channelsInfo = @layer.channelsInfo
...@@ -18,8 +21,8 @@ module.exports = class ChannelImage extends Image ...@@ -18,8 +21,8 @@ module.exports = class ChannelImage extends Image
for chan in @channelsInfo for chan in @channelsInfo
@file.seek chan.length, true @file.seek chan.length, true
width: -> @layer.width width: -> @_width
height: -> @layer.height height: -> @_height
channels: -> @layer.channels channels: -> @layer.channels
parse: -> parse: ->
...@@ -32,13 +35,13 @@ module.exports = class ChannelImage extends Image ...@@ -32,13 +35,13 @@ module.exports = class ChannelImage extends Image
@chan = chan @chan = chan
if chan.id < -1 if chan.id < -1
@width = @layer.mask.width @_width = @layer.mask.width
@height = @layer.mask.height @_height = @layer.mask.height
else else
@width = @layer.width @_width = @layer.width
@height = @layer.height @_height = @layer.height
@length = @width * @height @length = @_width * @_height
start = @file.tell() start = @file.tell()
@parseImageData() @parseImageData()
...@@ -48,7 +51,16 @@ module.exports = class ChannelImage extends Image ...@@ -48,7 +51,16 @@ module.exports = class ChannelImage extends Image
if finish isnt start + @chan.length if finish isnt start + @chan.length
@file.seek(start + @chan.length) @file.seek(start + @chan.length)
@width = @layer.width @_width = @layer.width
@height = @layer.height @_height = @layer.height
@processImageData() @processImageData()
parseImageData: ->
@compression = @parseCompression()
switch @compression
when 0 then @parseRaw()
when 1 then @parseRLE()
when 2, 3 then @parseZip()
else @file.seek(@endPos)
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