Skip to content

Instantly share code, notes, and snippets.

@adeolaawoyemi
Created October 25, 2010 02:22
Show Gist options
  • Save adeolaawoyemi/644289 to your computer and use it in GitHub Desktop.
Save adeolaawoyemi/644289 to your computer and use it in GitHub Desktop.
functions for resizing/scaling images proportionally
function resizeimage(img) {
var max_width = img.parent().width();
var max_height = img.parent().height();
//console.log('max dimensions are: %s x %s', max_width, max_height);
var width = img.width();
var height = img.height();
//console.log('img dimensions are: %s x %s', width, height);
var image = img;
(image.width()/image.parent().width()) > (image.height()/image.parent().height()) ?
image.css({'width':'100%'}) :
image.css({'height':'100%'});
}
function scaleSize(maxW, maxH, currW, currH) {
var ratio = currH / currW;
if (currW >= maxW &amp;&amp; ratio <= 1) {
currW = maxW;
currH = currW * ratio;
} else if (currH >= maxH) {
currH = maxH;
currW = currH / ratio;
}
return [currW, currH];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment