function resizeImage(image){ var oldwidth, oldheight; oldwidth = image.width; oldheight = image.height; if(image.height > image.width){ if(image.height > 120){ image.height = 120; image.width = Math.round((120*oldwidth)/oldheight); while(image.width > 160){ image.height = Math.round(0.9*image.height); image.width = Math.round(0.9*image.width); } } } else { if(image.width > 160){ image.width = 160; image.height = Math.round((160*oldheight)/oldwidth); } while(image.height > 120){ image.height = Math.round(0.9*image.height); image.width = Math.round(0.9*image.width); } } }