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

 All Forums
 Help Groups for Snitz Forums 2000 Users
 Help: MOD Implementation
 Dynamic Proportioning Mod
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

seven
Senior Member

USA
1037 Posts

Posted - 13 February 2003 :  08:10:59  Show Profile  Visit seven's Homepage
I am trying to implement a tweaked version of the avatar dynamic proportioning mod (for other purposes other than avatars) but I am running into a few snags.

The code highlited in red below sometimes causes an error, but the big issue is larger image files do not work correctly, the code returns 1 and 1 for width and height. It works fine on smaller sized images. Any ideas?



seven
Senior Member

USA
1037 Posts

Posted - 13 February 2003 :  08:12:41  Show Profile  Visit seven's Homepage
	' 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

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 1.25 seconds. Powered By: Snitz Forums 2000 Version 3.4.07