A general purpose PSD parser written in Coffeescript. Based off of PSD.rb.
Runs in both NodeJS and the browser (using browserify). There are still some pieces missing that are present in PSD.rb, such as layer comp filtering, a built-in renderer, and many layer info blocks. The eventual goal is full feature parity with PSD.rb.
Before installing from npm, you must install libpng, which is available on all popular package management systems. On OSX with homebrew, you can do brew install libpng
. The install success for node-png is currently hit or miss, so alternate image packages are currently under consideration.
Once your system is ready, simply add to your package.json dependencies or run npm install psd
.
PSD.js works almost exactly the same in the browser and NodeJS.
var PSD = require('psd');
var psd = PSD.fromFile("path/to/file.psd");
psd.parse();
console.log(psd.tree().export());
console.log(psd.tree().childrenAtPath('A/B/C')[0].export());
// You can also use promises syntax for opening and parsing
PSD.open("path/to/file.psd").then(function (psd) {
return psd.image.saveAsPng('./output.png');
}).then(function () {
console.log("Finished!");
});
var PSD = require('psd');
// Load from URL
PSD.fromURL("/path/to/file.psd").then(function(psd) {
document.getElementById('ImageContainer').appendChild(psd.image.toPng());
});
// Load from event, e.g. drag & drop
function onDrop(evt) {
PSD.fromEvent(evt).then(function (psd) {
console.log(psd.tree().export());
});
}