function downimage(imgd,maxwidth,maxheight){ var image=new image(); image.src=imgd.src; if(image.width>0 && image.height>0){ var rate = (maxwidth/image.width < maxheight/image.height)?maxwidth/image.width:maxheight/image.height; if(rate <= 1){ imgd.width = image.width*rate; imgd.height =image.height*rate; } } }