Home     Products      Support      Corporate     Sign In 
Support Knowledge Base, Article 21
Product
FileUp
Version
2.x
Title
HOWTO: Resizing a GIF image for display
Problem
SA-FileUp is commonly used to upload or download images files. Many customers would like to resize the image upon upload or download.
Solution
This script was supplied by an astute customer, Magnus Lindbergh of CreateIT web agency in Sweden. Thanks Magnus!
It assumes that the image has been uploaded to a database, but could easily be adapted when the image is uploaded to a file. For use with a file, use ASP's Scripting.FileSystemObject to read the first few bytes of the image.
<%
SQL = "SELECT BLOB "
SQL = SQL & "FROM objectIMAGE WHERE (((objectIMAGE.imageID)=" &
Request.QueryString("imageID") & "));"
Set Connection = Server.CreateObject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.RecordSet")
RS.Open SQL, "DSN=DN", 3, 3

Dim BitSet
ReDim BitSet (10)

For I = 0 to 10
BitSet(I) = RS.Fields("BLOB").GetChunk(1)
Next

' Calculate GIF width & height using bit 6-9

width = (256 * AscB(BitSet(7))) + AscB(BitSet(6))
height = (256 * AscB(BitSet(9))) + AscB(BitSet(8))

' Max width / height

MaxWidth  = 300
MaxHeight = 200


' Resize the image

iWidth = width
iHeight = height

If iWidth > MaxWidth Then
iHeight = iHeight * maxWidth / iWidth
iWidth = maxWidth

End If

If iHeight > MaxHeight Then
iWidth = iWidth * maxHeight / iHeight
iHeight = maxHeight
End If

' Store Values in Session variables

Session("sWidth") = iWidth
Session("sHeight") = iHeight

%>
This script must be executed before doing the binarywrite. This script will be called from the .asp page after executing the above script.

Using a HTML TAG like:

<img src="resize_gif.asp?imageID=<%=request.querystring("objectID")%>"
width="<%=Cint(Session("sWidth"))%>"
height="<%=Cint(Session("sHeight"))%>">
Note the use of Session("sWidth") & Session("sHeight"), which are calculated in the first script.
resize_gif.asp

<%
 MaxSize = 700000
 Response.Expires = 0
 Response.Buffer = TRUE
 Response.Clear
 Response.ContentType="image/gif"
 Set Connection = Server.CreateObject("ADODB.Connection")
 Connection.Open "DSN=DN"
 SQLB = "SELECT BLOB FROM objectIMAGE WHERE imageID ="
 SQLB = SQLB & Request.QueryString("imageID")
 Set rsBlob = Connection.Execute(SQLB)
 Response.BinaryWrite rsBlob("BLOB").getChunk(MaxSize)
 Response.End
%>
Created : 12/1/2002 12:00:00 AM (last modified : 5/19/1999 4:26:00 PM)
Rate this article!
Comments