Skip to content

Instantly share code, notes, and snippets.

@melvynhills
Created April 5, 2012 15:56
Show Gist options
  • Save melvynhills/2312114 to your computer and use it in GitHub Desktop.
Save melvynhills/2312114 to your computer and use it in GitHub Desktop.
Load local image files into the DOM
// http://html5doctor.com/drag-and-drop-to-server/
var acceptedTypes = {
'image/png': true,
'image/jpeg': true,
'image/gif': true
};
if (acceptedTypes[file.type] === true) {
var reader = new FileReader();
reader.onload = function (event) {
var image = new Image();
image.src = event.target.result;
image.width = 100; // a fake resize
document.body.appendChild(image);
};
reader.readAsDataURL(file);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment