function drawimage(mypic,w,h){ var flag=false; var image=new image(); image.src=mypic.src; if(image.width>0 && image.height>0){ flag=true; if(image.width/image.height>= w/h){ if(image.width>w){ mypic.width=w; mypic.height=(image.height*w)/image.width; } else{ mypic.width=image.width; mypic.height=image.height; } } else{ if(image.height>h){ mypic.height=h; mypic.width=(image.width*h)/image.height; } else{ mypic.width=image.width; mypic.height=image.height; } } } }