Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Avatar question, and ASP/VBScript in general
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Iron Heart
New Member

USA
66 Posts

Posted - 27 May 2001 :  06:49:53  Show Profile
Is there any way to determine the natural size of an image file using VBScript or VBSCript & javascript?

What I'm trying to do is to:

- get avatar's width & height
- take the highest of these two
- set it to 64, decrease the other one proportionally

So that all avatars come out nice and neat.

Is there a way to do it?

S.P.S.W. - My Forums

MorningZ
Junior Member

USA
169 Posts

Posted - 27 May 2001 :  11:14:47  Show Profile  Visit MorningZ's Homepage  Send MorningZ an AOL message
i've got this subroutine working

and then you could just use the returned height and width in the IMG tag's parameters

you could use something else like this snippet to keep the proportion


'Resize Image to max of 400 width or 300 height if neccessary
if Width > 65 or Height > 75 then
if Height > Width then
NewHeight = 75
NewWidth = cInt(cInt(Width) / (cInt(Height)/75))
else
NewWidth = 65
NewHeight = cInt(cInt(Height) / (cInt(Width)/65))
end if
End if


let me know if i put you on the right track.....

-Steve



Go to Top of Page

Iron Heart
New Member

USA
66 Posts

Posted - 28 May 2001 :  05:14:15  Show Profile
Thank you very much, I'm much obliged for the help.

I've changed these a bit, and here's the final product I'm using:


Sub GetPicFileInfo( i_sFilename, o_PicType, o_nWidth, o_nHeight )

i_sFilename = replace(i_sFilename, "/", "\", 1, -1, 1)
o_PicType = ""
o_nWidth = 0
o_nHeight = 0

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")
Set ts = fso.OpenTextFile("C:\www\someplacesomewhere.com\forums\" & i_sFilename)

On Error Resume Next
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

if o_nWidth > 64 or o_nHeight > 64 then
if o_nHeight > o_nWidth then
o_nWidth = cInt(o_nWidth * 64/o_nHeight)
o_nHeight = 64
else
o_nHeight = cInt(o_nHeight * 64/o_nWidth)
o_nWidth = 64
end if
end if
response.write " width=""" & o_nWidth & """ height=""" & o_nHeight & """"
Set ts = Nothing
Set fso = Nothing
End Sub


S.P.S.W. - My Forums
Go to Top of Page

MorningZ
Junior Member

USA
169 Posts

Posted - 28 May 2001 :  07:22:53  Show Profile  Visit MorningZ's Homepage  Send MorningZ an AOL message
good idea to combine the two



Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.26 seconds. Powered By: Snitz Forums 2000 Version 3.4.07