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';
var start = new Date();
PSD.open(file).then(function (psd) {
return psd.tree().descendants().forEach(function (node) {
psd.tree().descendants().forEach(function (node) {
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 () {
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
@includes ImageFormat.LayerRLE
constructor: (file, header, @layer) ->
@_width = @layer.width
@_height = @layer.height
super(file, header)
@channelsInfo = @layer.channelsInfo
......@@ -18,8 +21,8 @@ module.exports = class ChannelImage extends Image
for chan in @channelsInfo
@file.seek chan.length, true
width: -> @layer.width
height: -> @layer.height
width: -> @_width
height: -> @_height
channels: -> @layer.channels
parse: ->
......@@ -32,13 +35,13 @@ module.exports = class ChannelImage extends Image
@chan = chan
if chan.id < -1
@width = @layer.mask.width
@height = @layer.mask.height
@_width = @layer.mask.width
@_height = @layer.mask.height
else
@width = @layer.width
@height = @layer.height
@_width = @layer.width
@_height = @layer.height
@length = @width * @height
@length = @_width * @_height
start = @file.tell()
@parseImageData()
......@@ -48,7 +51,16 @@ module.exports = class ChannelImage extends Image
if finish isnt start + @chan.length
@file.seek(start + @chan.length)
@width = @layer.width
@height = @layer.height
@_width = @layer.width
@_height = @layer.height
@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