The latest JavaScript automatically displays pictures proportionally, proportionally compresses the picture display

Source: Internet
Author: User

The latest JavaScript automatically displays pictures proportionally, proportionally compresses the picture display<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">
<HTMLxmlns= "http://www.w3.org/1999/xhtml">
<Head>
<Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />
<title>The latest JavaScript automatically displays pictures proportionally, proportionally compresses the picture display</title>
<Scripttype= "Text/javascript">
functionAutoresizeimage (MaxWidth, MaxHeight, objimg) {
varIMG =NewImage ();
IMG.SRC = OBJIMG.SRC;
varHratio;
varWratio;
varRatio = 1;
varW = img.width;
varh = img.height;
Wratio = maxwidth/w;
Hratio = maxheight/h;
if(MaxWidth = = 0 && MaxHeight = = 0) {
Ratio = 1;
}Elseif(MaxWidth = = 0) {//
if(Hratio < 1) Ratio = Hratio;
}Elseif(MaxHeight = = 0) {
if(Wratio < 1) Ratio = Wratio;
}Elseif(Wratio < 1 | | Hratio < 1) {
Ratio = (wratio <= hratio? wratio:hratio);
}
if(Ratio < 1) {
w = w * Ratio;
H = h * Ratio;
}
Objimg.height = h;
Objimg.width = W;
}
</Script>
</Head>
<Body>
<BR/>
Original display (534 X 800)<BR/>
Onload= "Autoresizeimage (0,0,this)<BR/>
<ahref= "Http://p.blog.csdn.net/images/p_blog_csdn_net/feng_sundy/421506/o_09925c7bcead8c60f683298dacf497a6.jpg" Target= "_blank"><imgsrc= "Http://p.blog.csdn.net/images/p_blog_csdn_net/feng_sundy/421506/o_09925c7bcead8c60f683298dacf497a6.jpg" Border= "0"width= "0"Height= "0"onload= "Autoresizeimage (0,0,this)"alt= "534 X"/></a><BR/><BR/>
1. Press width 250 to compress, do not limit height proportionally<BR/>
Onload= "Autoresizeimage (250,0,this)"<BR/>
<ahref="#"Target= "_blank"><imgsrc= "Http://p.blog.csdn.net/images/p_blog_csdn_net/feng_sundy/421506/o_09925c7bcead8c60f683298dacf497a6.jpg" Border= "0"width= "0"Height= "0"onload= "Autoresizeimage (250,0,this)"alt= "X 374"/></a><BR/><BR/>
2. Press the height 250 compression, do not limit the width proportionally compression<BR/>
Onload= "Autoresizeimage (0,250,this)"<BR/>
<ahref="#"Target= "_blank"><imgsrc= "Http://p.blog.csdn.net/images/p_blog_csdn_net/feng_sundy/421506/o_09925c7bcead8c60f683298dacf497a6.jpg" Border= "0"width= "0"Height= "0"onload= "Autoresizeimage (0,250,this)"alt= "166 X"/></a><BR/><BR/>
3. Proportional compression by height 250 width 250<BR/>
Onload= "Autoresizeimage (250,250,this)"<BR/>
<ahref="#"Target= "_blank"><imgsrc= "Http://p.blog.csdn.net/images/p_blog_csdn_net/feng_sundy/421506/o_09925c7bcead8c60f683298dacf497a6.jpg" Border= "0"width= "0"Height= "0"onload= "Autoresizeimage (250,250,this)"alt= "X"/></a><BR/><BR/>
4. Aspect unequal proportional compression (X 512), when the height is constant, will automatically be compressed according to the height of the scale.<BR/>
Onload= "Autoresizeimage (400,512,this)"<BR/>
<ahref="#"Target= "_blank"><imgsrc= "Http://p.blog.csdn.net/images/p_blog_csdn_net/feng_sundy/421506/o_09925c7bcead8c60f683298dacf497a6.jpg" Border= "0"width= "0"Height= "0"onload= "Autoresizeimage (400,512,this)"alt= "341 X"/></a><BR/><BR/>
5. Aspect unequal proportional compression (X 600), when the width is constant, will be automatically compressed by the proportion of the width.<BR/>
Onload= "Autoresizeimage (300,600,this)"<BR/>
<ahref="#"Target= "_blank"><imgsrc= "Http://p.blog.csdn.net/images/p_blog_csdn_net/feng_sundy/421506/o_09925c7bcead8c60f683298dacf497a6.jpg" Border= "0"width= "0"Height= "0"onload= "Autoresizeimage (300,600,this)"alt= "X 449"/></a><BR/><BR/>
6. If the height and width of the picture are less than the maximum height and width of the compression, the picture will not be pulled up (shown by the original)<BR/>
Original 444 x 207, compressed to x 600, will keep the original display<BR/>
Onload= "Autoresizeimage (500,600,this)"<BR/>
<ahref="#"Target= "_blank"><imgsrc= "http://p.blog.csdn.net/images/p_blog_csdn_net/feng_sundy/242776/o_20070410_ B7409cd284a0f799a357uepcefa6ty0x.jpg "Border= "0"width= "0"Height= "0"onload= "Autoresizeimage (500,600,this)"alt= "444 X 207"/></a><BR/><BR/>
</Body>
</HTML>


Related Article

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.