Created
September 17, 2011 19:11
-
-
Save Themaister/1224240 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| function load_image(evt) { | |
| if (!(window.File && window.FileReader && window.FileList && window.Blob)) { | |
| alert("FileReader API not supported by this browser ..."); | |
| return; | |
| } | |
| var file = evt.target.files[0]; | |
| if (!file.type.match("image.*")) { | |
| alert("This is not an image file! :("); | |
| return; | |
| } | |
| var reader = new FileReader(); | |
| reader.onload = (function(file) { | |
| return function(e) { | |
| alert("File read!"); | |
| texture_.old_img = texture_.image; | |
| texture_.image = new Image(); | |
| texture_.image.onload = function() { | |
| if (texture_.image.width > 0 && texture_.image.height > 0) { | |
| try { | |
| set_image(texture_.image); | |
| } catch (e) { | |
| texture_.image = texture_.old_img; | |
| alert(e); | |
| } | |
| } else { | |
| texture_.image = texture_.old_img; | |
| } | |
| } | |
| texture_.image.src = e.target.result; | |
| } | |
| })(file); | |
| reader.readAsDataURL(file); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment