phillipbentonkelly
7/8/2015 - 5:31 PM

Scale Image based on proportions change of the parent http://www.ajaxblender.com/howto-resize-image-proportionally-using-javascript.html

Scale Image based on proportions change of the parent http://www.ajaxblender.com/howto-resize-image-proportionally-using-javascript.html

scaleSize: function(maxW, maxH, currW, currH){
	var ratio = currH / currW;

	if(currW >= maxW && ratio <= 1){
	  currW = maxW;
	  currH = currW * ratio;
	} else if(currH >= maxH){
	  currH = maxH;
	  currW = currH / ratio;
	} else {
	  if( currW > currH ){
	      currW = maxW;
	      currH = maxW * ratio;
	  }else{
	      currH = maxH;
	      currW = maxH / ratio;
	  }
	}
	return [ Math.round(currW), Math.round(currH) ];
}