var flag=false; function drawimage(imgd,width,height){ var image=new image(); image.src=imgd.src; if(image.width>0 && image.height>0){ flag=true; if(image.width/image.height>= width/height){ if(image.width>width){ imgd.width=width; imgd.height=(image.height*width)/image.width; }else{ imgd.width=image.width; imgd.height=image.height; } // imgd.alt=image.width+"×"+image.height; } else{ if(image.height>height){ imgd.height=height; imgd.width=(image.width*height)/image.height; }else{ imgd.width=image.width; imgd.height=image.height; } // imgd.alt=image.width+"×"+image.height; } } } //onload="javascript:drawimage(this,width,height);"