<!--#include file="conn.asp"-->
<%
Class Netout 
dim Image 
Private Sub Class_Initialize 
	set Image=CreateObject("Adodb.Stream") 
	Image.Mode=3 
	Image.Type=1 
	Image.Open 
End Sub 

Private Sub Class_Terminate 
	set Image=nothing 
End Sub 

Private Function Bin2Str(Bin) 
	Dim I, Str 
	For I=1 to LenB(Bin) 
		clow=MidB(Bin,I,1) 
		if ASCB(clow)<128 then 
			Str = Str & Chr(ASCB(clow)) 
		else 
			I=I+1 
			if I <= LenB(Bin) then
				Str = Str & Chr(ASCW(MidB(Bin,I,1)&clow)) 
			end if
		end if 
	Next 
	Bin2Str = Str 
End Function 
Private Function Num2Str(num,base,lens) 
	dim ImageInfos 
	ImageInfos = "" 
	while(num>=base) 
		ImageInfos = (num mod base) & ImageInfos 
		num = (num - num mod base)/base 
	wend 
	Num2Str = right(string(lens,"0") & num & ImageInfos,lens) 
End Function 

Private Function Str2Num(str,base) 
	dim ImageInfos 
	ImageInfos = 0 
	for i=1 to len(str) 
		ImageInfos = ImageInfos *base + cint(mid(str,i,1)) 
	next 
	Str2Num=ImageInfos 
End Function 

Private Function BinVal(bin) 
	dim ImageInfos 
	ImageInfos = 0 
	for i = lenb(bin) to 1 step -1 
		ImageInfos = ImageInfos *256 + ascb(midb(bin,i,1)) 
	next 
	BinVal=ImageInfos 
End Function 

Private Function BinVal2(bin) 
	dim ImageInfos 
	ImageInfos = 0 
	for i = 1 to lenb(bin) 
		ImageInfos = ImageInfos *256 + ascb(midb(bin,i,1)) 
	next 
	BinVal2=ImageInfos 
End Function 

Function getImageSize(ImageFile) 
	if ImageFile="" then exit function
	dim ImageInfos(3) 
	Image.LoadFromFile(ImageFile) 
	bFlag=Image.read(3) 
	select case hex(binVal(bFlag)) 
	case "4E5089": 
		Image.read(15) 
		ImageInfos(0)="PNG" 
		ImageInfos(1)=BinVal2(Image.read(2)) 
		Image.read(2) 
		ImageInfos(2)=BinVal2(Image.read(2)) 
	case "464947": 
		Image.read(3) 
		ImageInfos(0)="GIF" 
		ImageInfos(1)=BinVal(Image.read(2)) 
		ImageInfos(2)=BinVal(Image.read(2)) 
	case "535746": 
		Image.read(5) 
		binData=Image.Read(1) 
		sConv=Num2Str(ascb(binData),2 ,8) 
		nBits=Str2Num(left(sConv,5),2) 
		sConv=mid(sConv,6) 
		while(len(sConv)<nBits*4) 
			binData=Image.Read(1) 
			sConv=sConv&Num2Str(ascb(binData),2 ,8) 
		wend 
		ImageInfos(0)="SWF" 
		ImageInfos(1)=int(abs(Str2Num(mid(sConv,1*nBits+1,nBits),2)-Str2Num(mid(sConv,0*nBits+1,nBits),2))/20) 
		ImageInfos(2)=int(abs(Str2Num(mid(sConv,3*nBits+1,nBits),2)-Str2Num(mid(sConv,2*nBits+1,nBits),2))/20) 
	case "FFD8FF": 
		do 
		do: p1=binVal(Image.Read(1)): loop while p1=255 and not Image.EOS 
		if p1>191 and p1<196 then exit do else Image.read(binval2(Image.Read(2))-2) 
		do:p1=binVal(Image.Read(1)):loop while p1<255 and not Image.EOS 
		loop while true 
		Image.Read(3) 
		ImageInfos(0)="JPG" 
		ImageInfos(2)=binval2(Image.Read(2)) 
		ImageInfos(1)=binval2(Image.Read(2)) 
	case else: 
		if left(Bin2Str(bFlag),2)="BM" then 
			Image.Read(15) 
			ImageInfos(0)="BMP" 
			ImageInfos(1)=binval(Image.Read(4)) 
			ImageInfos(2)=binval(Image.Read(4)) 
		else 
			ImageInfos(0)="" 
		end if 
	end select 
	ImageInfos(3)="width=""" & ImageInfos(1) &""" height=""" & ImageInfos(2) &"""" 
	getimagesize=ImageInfos 
End Function 
End Class 
'########################
Function ObjectExists(oClass)
'########################
	On Error Resume Next
	Set obj=Server.CreateObject(oClass)
	If Err Then ObjectExists=False Else ObjectExists=True
	Set Obj=Nothing
End Function
Set ImageFile=new Netout

FileName=trim(request("FileName"))
if request("location")="admin" then
	FilePath=server.MapPath("admin/"&FileName)
else
	FilePath=server.MapPath(FileName)
end if
SystemPath=Trim(Request("Path"))
ImageSize=ImageFile.getImageSize(FilePath) 

CurrentFile=trim(request("File"))
if CurrentFile="img" then
	MaxWidth=60000:MaxHeight=60000
elseif request("location")="manage" then
	MaxWidth=40:MaxHeight=40
else
	MaxWidth=rs5("MaxWidth"):MaxHeight=rs5("MaxHeight")
end if

width=cint(ImageSize(1)):height=cint(ImageSize(2))
m=width/MaxWidth:n=height/MaxHeight
if (width>MaxWidth) or (height>MaxHeight) then
	if m>n then
		preWidth=MaxWidth:preHeight=height/m
	elseif m<n then
		preHeight=MaxHeight:preWidth=width/n
	else
		preWidth=MaxWidth:preHeight=MaxHeight
	end if
else
	preWidth=width:preHeight=height
end if
randomize
ranNum=int(900*rnd)+100
if preWidth>650 then
 beisu=preWidth/650
 preWidth=preWidth/beisu
End if
if Request("location")="admin" and ObjectExists("Persits.Jpeg") then
s_filename=Replace(FileName,"UploadImages","UploadImages/s")
response.Write("document.write("&chr(34)&"<img src='"&RS5(2)&"/admin/"&s_filename&"' width="&preWidth&" border='0' class=simgb align='absmiddle'>"&chr(34)&")")
Else
if Trim(Request("File"))<>"big_img" then
if Trim(Request("jpgsize"))="s" and ObjectExists("Persits.Jpeg") then
s_filename=Replace(FileName,"UploadImages","UploadImages/s")
response.Write("document.write("&chr(34)&"<img src='"&RS5(2)&s_FileName&"'style='-moz-opacity:0.5; filter:alpha(opacity=80);cursor:hand;' onmouseover='this.style.MozOpacity=1;this.filters.alpha.opacity=100' onmouseout='this.style.MozOpacity=0.5;this.filters.alpha.opacity=80' border='0' class=simgb align='absmiddle'>"&chr(34)&")")
Elseif Trim(Request("jpgsize"))="s" or Trim(Request("jpgsize"))="" then
if Session("manage")="" then
response.Write("document.write("&chr(34)&"<img src='"&RS5(2)&FileName&"' width="&preWidth&" border='0' class=simgb align='absmiddle'>"&chr(34)&")")
Else
response.Write("document.write("&chr(34)&"<img src='"&RS5(2)&"admin/"&FileName&"' width="&preWidth&" border='0' class=simgb align='absmiddle'>"&chr(34)&")")
end if
End if
Else
response.Write("document.write("&chr(34)&"<img src='"&RS5(2)&FileName&"' border='0' class=simgb align='absmiddle'>"&chr(34)&")")
End if
End if
%>
