function calculateAspectRatioFit(srcWidth, srcHeight, maxWidth, maxHeight) {

    var ratio = [maxWidth / srcWidth, maxHeight / srcHeight ];
    ratio = Math.min(ratio[0], ratio[1]);

    return { width:srcWidth*ratio, height:srcHeight*ratio };
 }
/**
  * Conserve aspect ratio of the orignal region. Useful when shrinking/enlarging
  * images to fit into a certain area.
  *
  * @param {Number} srcWidth Source area width
  * @param {Number} srcHeight Source area height
  * @param {Number} maxWidth Fittable area maximum available width
  * @param {Number} maxHeight Fittable area maximum available height
  * @return {Object} { width, heigth }
  */
Conserve aspect ratio of the orignal region. Useful when shrinking/enlarging
images to fit into a certain area.


Conserve aspect ratio of the orignal region . Useful when shrinking / enlarging images to fit into a certain area .
function calculateAspectRatioFit(srcWidth, srcHeight, maxWidth, maxHeight) {
    var ratio = [maxWidth / srcWidth, maxHeight / srcHeight ];
    ratio = Math.min(ratio[0], ratio[1]);
    return { width:srcWidth*ratio, height:srcHeight*ratio };
 }
function calculateAspectRatioFit ( srcWidth , srcHeight , maxWidth , maxHeight ) { var ratio = [ maxWidth / srcWidth , maxHeight / srcHeight ] ; ratio = Math . min ( ratio [ 0 ] , ratio [ 1 ] ) ; return { width : srcWidth * ratio , height : srcHeight * ratio } ; }
Conserve aspect ratio of the orignal region.
Conserve aspect ratio of the orignal region .