There are many ASP components that generate thumbnails on the Internet. If your virtual space does not support registering new components, you may feel that your website is losing its color. Xinqing is not talented, and combined with online resources, she wrote a component-free thumbnail program for reference only.
Let's take a look at the basics first. First of all, we know that the following code is displayed on the page:
<imgsrc="pic.gif"border="0"width="300"height="260">
src is the image path, border controls the edge width of the image, width is the length of the image, and height is the height of the image. The generation of thumbnails is actually scaling on the original size. But generally, in order to minimize distortion, we will scale to scale. Therefore, obtaining the length and width of the picture becomes the focus of generating thumbnails.
Here are the steps to write a component-free thumbnail:
1. Get the image size without components
I saw an article using ASCII code to obtain image sizes without components when I first learned ASP. Later I tried it and found that when I got the size of jpg-like images, I checked it online and found that many websites reprinted this program, but none of them pointed out the flaws of this program, let alone the solution to the flaws. Later I went Googled and finally found an article introducing the use of ADODB.stream to obtain image sizes. I tried it by modifying the code inside according to the method introduced. The effect is really good. Now I will take it out and share it with you:
Use ADODB.stream to obtain common class <% of image size
'///////////////// GPS: GetPictureSize/////////////
'///////////////////////////////
'/////////////CitedByLeon (Xinqing) August 11, 2005 //////////////////
ClassGPS
Dimaso
PrivateSubClass_Initialize
Setaso=CreateObject("Adodb.Stream")
aso.Mode=3
aso.Type=1
aso.Open
EndSub
PrivateSubClass_Terminate
setaso=nothing
EndSub
PrivateFunctionBin2Str(Bin)
DimI,Str
ForI=1toLenB(Bin)
clow=MidB(Bin,I,1)
ifAscB(clow)<128then
Str=Str&Chr(ASCB(clow))
Else
I=I+1
ifI<=LenB(Bin)thenStr=Str&Chr(ASCW(MidB(Bin,I,1)&clow))
endIf
Next
Bin2Str=Str
EndFunction
PrivateFunctionNum2Str(num, base,lens)
'GPS(2005-8-11)
dimret
ret=""
While(num>=base)
ret=(nummodbase)&ret
num=(num-nummodbase)/base
wend
Num2Str=right(string(lens,"0")&num&ret,lens)
EndFunction
PrivateFunctionStr2Num(str,base)
'GPS(2005-8-11)
dimret
ret=0
fori=1tolen(str)
ret=ret*base+cint(mid(str,i,1))
next
Str2Num=ret
EndFunction