This article mainly introduces the method of cropping thumbnails with fixed proportions of ASP. Friends who need it can refer to it.
There are two general methods to generate thumbnails:
The first type: Scale into a fixed-size small picture
The second type: small pictures that scale to equal proportions
The disadvantage of the first method is that it will deform the picture, such as a slim girl turning into a fat girl
The disadvantage of the second method is that if the picture is displayed in a table and the aspect ratio of the picture is different from this table, it cannot fill the entire table, leaving a gap, which is not good-looking.
The method introduced here is to fix the scale cropping , using the aspjpeg component, that is, the aspect ratio of the generated thumbnail is fixed, but will not deform. If the aspect ratio of the original image is greater than the set aspect ratio, the excess pictures on both sides will be automatically cut out; if the aspect ratio of the original image is less than the set aspect ratio, the excess pictures on the upper and lower sides will be automatically cut out; if the aspect ratio of the original image is less than the set aspect ratio, the excesses on the upper and lower sides will be automatically cut out. picture.
?
- FunctionMakePic(sourcpic,newwidth,newheight,destpic)
- Onerrorresumenext
- MakePic=false
- SetJpeg=Server.CreateObject(Persits.Jpeg)
- ifErrthen
- response.Write (Error: The aspjpeg component is not installed in the space)
- response.end
- endif
- Jpeg.Quality=100
- Jpeg.Opensourcpic
- jpeg.PreserveAspectRatio=True' equal ratio scaling
- ifjpeg.OriginalWidth/jpeg.OriginalHeight>newwidth/newheightthen'It's too flat, you need to cut off the left and right parts
- jpeg.Height=newheight
- jpeg.cropCInt((jpeg.Width–newwidth)/2),0,CInt((jpeg.Width–newwidth)/2)+newwidth,newheight
- else'It's too high, cut off the upper and lower parts
- jpeg.Width=newwidth
- jpeg.crop0,CInt((jpeg.Height–newheight)/2),newwidth,CInt((jpeg.Height–newheight)/2)+newheight
- endif
- Jpeg.Savedestpic
- iferr.number=0thenMakePic=True
- Jpeg.Close
- SetJpeg=Nothing
- Endfunction