' Resample and proportinalize profile image
Sub GetPicFileInfo( i_sPath, i_sFilename, i_nWidth, i_nHeight, i_nTitle, i_nAltimage )
Dim fso, ts
Dim GIF_MARKER, JPG_MARKER
GIF_MARKER = "GIF8"
JPG_MARKER = Chr(&HFF) & Chr(&HD8) & Chr(&HFF) & Chr(&HE0)
Set fso = CreateObject("Scripting.FileSystemObject")
'On Error Resume Next
Set ts = fso.OpenTextFile(Server.MapPath(i_sPath & i_sFilename))
If Err.Number <> 0 Then
Err.Clear
Set ts = fso.OpenTextFile(i_sPath & i_noimage)
End if
Select Case ts.Read(4)
Case GIF_MARKER
o_PicType = "GIF"
ts.Skip(2)
If Err.Number <> 0 Then
Exit Sub
End If
o_nWidth = Asc(ts.Read(1)) + ( Asc(ts.Read(1))* 256 )
o_nHeight = Asc(ts.Read(1)) + ( Asc(ts.Read(1))* 256 )
Case JPG_MARKER
o_PicType = "JPG"
Dim byteVal, bDone
bDone = False
byteVal = Asc(ts.Read(1))
Do While Not ts.AtEndOfStream And byteVal <> &HD8 And Not bDone
'look for the next marker (xFF)
Do While Not ts.AtEndOfStream And byteVal <> &HFF
byteVal = Asc(ts.Read(1))
Loop
'Get past any repeated xFF markers
Do While Not ts.AtEndOfStream And byteVal = &HFF
byteVal = Asc(ts.Read(1))
Loop
'Check out the marker
'if this is the width/height section then read the values
If ((byteVal >= &HC0) And (byteVal <= &HC3)) Then
ts.Skip(3)
If Err.Number <> 0 Then
Exit Sub
End If
If Not ts.EOF Then
o_nHeight = (Asc(ts.Read(1)) * 256) + Asc(ts.Read(1))
o_nWidth = (Asc(ts.Read(1)) * 256) + Asc(ts.Read(1))
bDone = True
End If
Else
'this is a comment or other stuff we are not interested in.
'we must read the size and then skip over this section
Dim nSectionLength
nSectionLength = (Asc(ts.Read(1)) * 256) + Asc(ts.Read(1))
'NOTE: we subtract two since from the size since we already
'are past the length bytes which are included in the size
ts.Skip(nSectionLength - 2)
byteVal = Asc(ts.Read(1))
If Err.Number <> 0 Then
Exit Sub
End If
End If
Loop
End Select
maxwidth = i_nWidth
maxheight = i_nHeight
if o_nWidth > maxwidth or o_nHeight > maxheight then
if o_nWidth > maxwidth then
o_nHeight = cInt(o_nHeight * maxwidth/o_nWidth)
o_nWidth = maxwidth
if (o_nHeight > maxheight) then
o_nWidth = cInt(o_nWidth * maxheight/o_nHeight)
o_nHeight = maxheight
end if
elseif o_nHeight > maxheight then
o_nWidth = cInt(o_nWidth * maxheight/o_nHeight)
o_nHeight = maxheight
if (o_nWidth > maxwidth) then
o_nHeight = cInt(o_nHeight * maxwidth/o_nWidth)
o_nWidth = maxwidth
end if
end if
end if
Response.Write "<img src=""" & i_sPath & i_sFilename & """ Width=""" & o_nWidth & """ Height=""" & o_nHeight & """" & _
" Title=""" & i_nTitle & """ border=""1"" align=""right"">" & vbNewline
Set ts = Nothing
Set fso = Nothing
End Sub