B2G/gaia/apps/camera/js/filmstrip.js
// thumbnail image as a blob and pass it to the callback.
thumbnail image as a blob and pass it to the callback.
thumbnail image as a blob and pass it to the callback .
function createThumbnailFromImage(img, callback) {
    var canvas = document.createElement('canvas');
    var context = canvas.getContext('2d');
    canvas.width = THUMBNAIL_WIDTH;
    canvas.height = THUMBNAIL_HEIGHT;
    var imgwidth = img.width;
    var imgheight = img.height;
    var scalex = canvas.width / imgwidth;
    var scaley = canvas.height / imgheight;
    var scale = Math.max(scalex, scaley);
    var w = Math.round(THUMBNAIL_WIDTH / scale);
    var h = Math.round(THUMBNAIL_HEIGHT / scale);
    var x = Math.round((imgwidth - w) / 2);
    var y = Math.round((imgheight - h) / 2);
    context.drawImage(img, x, y, w, h,
                      0, 0, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
    canvas.toBlob(callback, 'image/jpeg');
  }
function createThumbnailFromImage ( img , callback ) { var canvas = document . createElement ( 'canvas' ) ; var context = canvas . getContext ( '2d' ) ; canvas . width = THUMBNAIL_WIDTH ; canvas . height = THUMBNAIL_HEIGHT ; var imgwidth = img . width ; var imgheight = img . height ; var scalex = canvas . width / imgwidth ; var scaley = canvas . height / imgheight ; var scale = Math . max ( scalex , scaley ) ; var w = Math . round ( THUMBNAIL_WIDTH / scale ) ; var h = Math . round ( THUMBNAIL_HEIGHT / scale ) ; var x = Math . round ( ( imgwidth - w ) / 2 ) ; var y = Math . round ( ( imgheight - h ) / 2 ) ; context . drawImage ( img , x , y , w , h , 0 , 0 , THUMBNAIL_WIDTH , THUMBNAIL_HEIGHT ) ; canvas . toBlob ( callback , 'image/jpeg' ) ; }
thumbnail image as a blob and pass it to the callback.
thumbnail image as a blob and pass it to the callback .
// Create a thumbnail image // Take the larger of the two scales: we crop the image to the thumbnail // Calculate the region of the image that will be copied to the // canvas to create the thumbnail // Draw that region of the image into the canvas, scaling it down