ASP crop thumbnails using AspJpeg fixed scale

Source: Internet
Author: User

There are two common ways to generate thumbnails:

One is a small picture scaled to a fixed size

Second, 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", in other words, 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.

Copy to Clipboard

What to reference: [www.veryhuo.com]

' ===============================================

' Generate a new size picture

' Failed return false, successful return true

' sourcpic-source picture absolute Path, newwidth-new picture wide, newheight-new picture high, destpic-target picture Absolute path

' ===============================================

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 does not have aspjpeg components installed")

Response.End

End If

jpeg.quality = 100

Jpeg.open Sourcpic

Jpeg. Preserveaspectratio = True ' equal scaling

If JPEG. Originalwidth/jpeg. OriginalHeight > Newwidth/newheight Then ' too flat to cut off the left and right parts

Jpeg. Height = Newheight

Jpeg.crop CInt (JPEG. Width–newwidth)/2), 0,cint (JPEG. Width–newwidth)/2 +newwidth,newheight

Else ' too high to cut off the upper and lower parts

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

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.