Skip to content

Instantly share code, notes, and snippets.

@imaya
Created September 22, 2012 09:24
Show Gist options
  • Save imaya/3765648 to your computer and use it in GitHub Desktop.
Save imaya/3765648 to your computer and use it in GitHub Desktop.
psd.js demo script
NodeList.prototype.forEach = Array.prototype.forEach;
window.addEventListener('DOMContentLoaded', function() {
document.getElementById('file').addEventListener('change', onFileSelected, false);
function onFileSelected(e) {
var file = document.getElementById("file").files[0];
var reader = new FileReader();
// remove all canvas
document.querySelectorAll('canvas').forEach(function(element) {
var parent = element.parentNode;
parent.removeChild(element);
});
reader.onload = function(e) {
var input = new Uint8Array(e.target.result);
var parser = new PSD.Parser(input);
parser.parse();
// image data
document.getElementById('target').appendChild(parser.imageData.createCanvas(parser.header));
console.log("PSD.Parser:", parser);
};
reader.readAsArrayBuffer(file);
e.preventDefault();
}
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment