Created
October 25, 2010 02:22
-
-
Save adeolaawoyemi/644289 to your computer and use it in GitHub Desktop.
functions for resizing/scaling images proportionally
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 && 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