When processing the thumbnail of a webpage image, it is difficult to ensure the uniform size of the image. Setting the image size directly causes the image to be stretched and blurred, the code described in this article can automatically adjust the image size proportionally after the image is loaded.
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "imageautozoom. aspx. cs" inherits = "ui_imageautozoom" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> JS scales webpage images proportionally-by wangtao </title>
<SCRIPT type = "text/JavaScript" src = "../MISC/JS/CORE/jquery. js"> </SCRIPT>
</Head>
<Body>
<SCRIPT type = "text/JavaScript">
Function imageautozoom (IMG, fitwidth, fitheight)
{
VaR image = new image ();
Image. src = IMG. SRC;
If (image. width> 0 & image. Height> 0)
{
If (image. width/image. Height> = fitwidth/fitheight)
{
If (image. width> fitwidth)
{
IMG. width = fitwidth;
IMG. Height = (image. Height * fitwidth)/image. width;
}
Else if (image. Hight> fitheight)
{
IMG. Height = fitheight;
IMG. width = (image. Width * fitheight)/image. height;
}
Else
{
IMG. width = fitwidth;
IMG. Height = fitheight;
}
}
}
}
</SCRIPT>
<Form ID = "imageautozoomform" runat = "server">
<Div>
</Div>
</Form>
</Body>
</Html>
When the image is too large, the page will be pulled, so it is best to set the height and width to reduce the pull range. Although this is not very technical, it is very practical. Most websites use images more or less.