Control picture scaling code in Web pages

Source: Internet
Author: User

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

Control picture scaling code in the page network, in general, it is very difficult to do this, because the small map from the database call out when the small, and when the call of the picture is high-definition digital photos, you know that there are many headaches, completely tabel squeezed not like a human face, all squeezed broken, ugly to see people ah, To control the picture in a certain size scaling, I think of is using JavaScript, and finally written out, tested n many back before successful, please see the code:

The front page plus (note that JavaScript is case-sensitive, I do not like the least of him, you do not have to pay attention to, I have written a test finished before issued to share, direct replication is not a problem)

<script language= "JavaScript" >


<!--


//Picture scaled


var flag=false;


function DrawImage (IMGD) {


var image=new image ();


var iwidth = 480; Define allowable picture width


var iheight = 530; Define Allow picture height


image.src=imgd.src;


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


flag=true;


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+ "x" +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;


        }


imgd.alt=image.width+ "x" +image.height;


        }


        }


        }


//Call:


//-->


</script>

Show the picture in the body

<img src= "Picture call path. jpg" Border=0 >

OK, this is done, that whether small or large picture, you can only swim in the 480x530.

Testimonials: 8630.html "> Sometimes feel that writing a program is so happy, as if everything in the grip, because learned something." Who has the simpler, please share the technology!

This article originates from: Peace Alliance---ASP Technology Alliance area http://www.hp8858.com Reprint please keep the link, thank you.

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.