Javascript输出图片

按比例输出,不会令图片变形!<br><br>代码如下<br><br><table width="90%" cellspacing="1" cellpadding="0" border="0" class="ubb_code"><tbody><tr>
<td>&lt;script language="JavaScript"&gt; <br>function showimage(imageUrl,size,id) { <br>var imgObj = new Image() <br>imgObj.src = imageUrl; <br>if (id==""){ id="" } <br>if (id==1){ id=" align=left" } <br>if (id==2){ id=" align=right" } <br>if (id==3){ id=" align=absmiddle" } <br>if(imgObj.width &gt; imgObj.height) { <br>incp("&lt;img hspace=4 src="+imgObj.src+" id=infoPicture height=" + imgObj.height*size/imgObj.width + " width=" + size + ""+id+" /&gt;"); <br>} else if(imgObj.width &lt; imgObj.height) { <br>incp("&lt;img hspace=4 src="+imgObj.src+" id=infoPicture height=" + size + " width="+ imgObj.width*size/imgObj.height +""+id+" /&gt;"); <br>} else { <br>incp("&lt;img hspace=4 src="+imgObj.src+" id=infoPicture height=" + size + " width="+ size + ""+id+" /&gt;"); <br>} <br>} <br>&lt;/script&gt;<br>
</td>
        </tr></tbody></table>
<br><br>调用:<br><br>&lt;script language="JavaScript"&gt;showimage('图片路径',宽度数值,位置设置);&lt;/script&gt;<br><br>位置说明:1 = 左对齐<br><br>2 = 右对齐<br><br>3 = 绝对中间

你可能感兴趣的:(JavaScript)