Using JS automatic generation and other proportions of the sketch

Source: Internet
Author: User
JS <!--
This example shows that proportional thumbnails are automatically displayed when the picture is loaded. When doing Web applications will often encounter customers upload a large picture, but when the display of the outline of the height and width than manually set, because the shape of the picture will cause the display deformation, here with a small script to solve this problem, You can modify it to make it more generic, such as adding an img parameter to the wa_setimgautosize () function, and then sending yourself to call the function in the picture's onload= event.
-->
<HTML>
<HEAD>
<TITLE> demo picture and so on scale shrink </TITLE>
<script>
function Wa_setimgautosize ()
{
var img=document.all.img1;//get Pictures
var maxwidth=200;//set Picture width limit
var maxheight=100;//set Picture height limit
var heightwidth=img.offsetheight/img.offsetwidth;//set aspect ratio
var widthheight=img.offsetwidth/img.offsetheight;//set ratio of width to height
if (img.readystate!= "complete") return false;//ensure that the picture is fully loaded
if (img.offsetwidth>maxwidth) {
Img.width=maxwidth;
Img.height=maxwidth*heightwidth;
}
if (img.offsetheight>maxheight) {
Img.height=maxheight;
Img.width=maxheight*widthheight;
}
}
</script>
</HEAD>
<BODY>

<br>
<input id=inp type= "file" onpropertychange= "Img1.src=this.value;" >
</BODY>
</HTML>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.