javascript如何实现图片按比例缩放具体实例代码

javascript如何实现图片按比例缩放具体实例代码,为大家提供的javascript图片缩放代码,希望可以给有需要的朋友带来帮助,别让图片把页面撑破了真的很实用的javascript源码哦。

function resizeimg(ImgD,iwidth,iheight) {
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+”×”+image.height;
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;

}

以上就是图片按比例缩小放大的js源码,谢谢支持! 本文链接地址: javascript如何实现图片按比例缩放具体实例代码