method of ASP fixed proportional clipping thumbnail--Application techniques

Source: Internet
Author: User

There are two common ways to generate thumbnails:

First: small pictures scaled to a fixed size

The second type: zoom into equal proportions of small pictures

The disadvantage of the first method is that it distorts the picture, such as a slim mm becoming a fat mm

The disadvantage of the second method is that if the picture is displayed in a table, and the picture's width-height ratio is different from this one, it can't fill the entire table, leaving a void, not good-looking.

The method described here is " fixed scale cropping ," using the AspJpeg component, which means that the resulting thumbnail width ratio is fixed, but not distorted. If the width of the original image is greater than the set width and height ratio, it will automatically cut off the left and right side of the figure, if the original width of the original ratio is less than the set width and height ratio, will automatically cut off the upper and lower redundant graphs.

Function Makepic (sourcpic,newwidth,newheight,destpic) on 
Error Resume Next 
makepic=false 
Set Jpeg = Server.CreateObject ("Persits.jpeg") 
if ERR then 
response. Write ("Error: Space not installed AspJpeg component") 
Response.End end 
if 
jpeg.quality = 
jpeg.open sourcpic 
Jpeg. Preserveaspectratio = True ' equal to scaling 
if jpeg. Originalwidth/jpeg. OriginalHeight > Newwidth/newheight Then ' too flat to cut off the left and right parts of the 
jpeg. Height = Newheight 
jpeg.crop CInt (jpeg. Width–newwidth)/2), 0,cint (JPEG. Width–newwidth)/2 +newwidth,newheight 
Else ' is too high to cut off the upper and lower part of the 
JPEG. Width = Newwidth 
jpeg.crop 0,cint (jpeg. Height–newheight)/2), Newwidth,cint (JPEG. Height–newheight)/2) +newheight end 
if 
jpeg.save destpic 
if err.number=0 
then makepic=true Jpeg.close 
Set jpeg=nothing end 
function

The above is the introduction of ASP using AspJpeg fixed-scale clipping thumbnails of the implementation of the method, I hope to help you learn.

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.