function imageResize(img,maxWidth,maxHeight,tryTimes){
    var tryTimes=tryTimes||0;
    if(img.width>0 && img.height>0){ 
        var rate = Math.min(maxWidth/img.width,maxHeight/img.height);
        if(rate <= 1){
            img.width *=rate;
            img.style.marginTop=Math.max((maxHeight-img.height)/2,0)+"px"; 
        }
    }
    else{
        if(tryTimes<3){ setTimeout(proxy(imageResize,img,maxWidth,maxHeight,++tryTimes),50);}
        else{
             img.width=maxWidth;
             img.height=maxHeight;
             img.style.marginTop="0px"
        }
    }
}
