Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Use createObjectURL if available so you can avoid loading image into memory #1

Merged
merged 1 commit into from

2 participants

@ryanseddon

Abstracted out image creation into separate function. Detect support for createObjectURL and use that over FileReader

@codepo8 codepo8 merged commit 84fa5ec into codepo8:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 3, 2012
  1. @ryanseddon
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 11 deletions.
  1. +21 −11 canvasthumber.js
View
32 canvasthumber.js
@@ -42,26 +42,36 @@
}
};
function getfiles( ev ) {
- var files = ev.dataTransfer.files;
+ var files = ev.dataTransfer.files,
+ url = window.URL || window.webkitURL,
+ objURL = url.createObjectURL || false;
+
if ( files.length > 0 ) {
var i = files.length;
while ( i-- ) {
var file = files[ i ];
if ( file.type.indexOf( 'image' ) === -1 ) { continue; }
- var reader = new FileReader();
- reader.readAsDataURL( file );
- reader.onload = function ( ev ) {
- var img = new Image();
- img.src = ev.target.result;
- img.onload = function() {
- grabformvalues();
- imagetocanvas( this, thumbwidth, thumbheight, crop, background );
+ if(objURL) {
+ loadImage(url.createObjectURL(file));
+ } else {
+ var reader = new FileReader();
+ reader.readAsDataURL( file );
+ reader.onload = function ( ev ) {
+ loadImage(ev.target.result);
};
- };
+ }
}
}
ev.preventDefault();
- };
+ }
+ function loadImage(file) {
+ var img = new Image();
+ img.src = file;
+ img.onload = function() {
+ grabformvalues();
+ imagetocanvas( this, thumbwidth, thumbheight, crop, background );
+ };
+ }
function grabformvalues() {
thumbwidth = document.querySelector( '#width' ).value;
thumbheight = document.querySelector( '#height' ).value;
Something went wrong with that request. Please try again.