//图片大小控制ImgD图片路径,ImgW是宽或高
        function DrawImage(ImgD,ImgW){
            var image=new Image();
            image.src=ImgD.src;

            if(image.width>0 && image.height>0){

                if(image.width/image.height>= 1){
                    if(image.width>ImgW){
                        ImgD.width=ImgW;
                        ImgD.height=(image.height*ImgW)/image.width;
                    }else{
                        ImgD.width=image.width;
                        ImgD.height=image.height;
                    }
                    ImgD.alt=image.width+"×"+image.height;
                }
                else{
                    if(image.height>ImgW){
                        ImgD.height=ImgW;
                        ImgD.width=(image.width*ImgW)/image.height;
                    }else{
//ImgD.width=(image.width*ImgW)/image.height;
                        ImgD.width=image.width;
                        ImgD.height=image.height;
                    }
                    ImgD.alt=image.width+"×"+image.height;
                }
            }
       
            console.log(ImgD); // 里面有图片的信息,拿出来用

        }

 

相关文章:

  • 2021-10-20
  • 2021-08-29
  • 2021-11-09
  • 2021-11-23
  • 2021-07-30
猜你喜欢
  • 2021-11-29
  • 2021-11-06
  • 2021-05-22
  • 2021-10-05
  • 2022-01-04
相关资源
相似解决方案