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