Created
September 22, 2012 09:24
-
-
Save imaya/3765648 to your computer and use it in GitHub Desktop.
psd.js demo script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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