instar4per
Programmer
Despite this being a web application, I am asking here, because the core of it is done in VB.
I have an ASP script which accepts an uploaded image ( using the FreeASPUpload class, ), and passes the temporary file's name to a custom component, which is supposed to do the following:
Load the image into an IPicture variable, using LoadPicture.
Convert the image to a DIB and resize.
Use the Intel JPEG library and save the image as a temporary JPEG.
Pass the temporary name back to the ASP script
Open the temporary file as an ADODB Stream, and insert it into a database.
Eventually, pull the data from the database, and pass it as a JPEG file back to the client.
I had all of this working. I modified the math on my resizing code, and suddenly it seems as though the component is now producing images that are no greater than 256 colors. See:
The DIB and JPEG code I am using comes from a project on Planet Source Code, -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Here is my full class code:
Option Explicit
Dim tmpFile As String
Dim mImage As IPicture
Dim DIB As cDIBSection
Private mPath As String
Public Property Let Path(New_Path As String)
Dim i As Long
If Right(New_Path, 1) <> "\" Then New_Path = New_Path & "\"
Randomize
For i = 1 To 20
tmpFile = tmpFile & Chr(65 + Rnd() * 23)
Next
tmpFile = New_Path & tmpFile & ".jpg"
End Property
Public Function LoadImage(sFile) As Boolean
LoadImage = True
On Error Resume Next
Set mImage = LoadPicture(sFile)
If Err.Number Then
LoadImage = False
Exit Function
End If
Set DIB = New cDIBSection
Kill sFile
End Function
Public Function Picture() As IPicture
Set Picture = mImage
End Function
Public Function MakeThumb()
Dim fAspect As Single
Dim bTaller As Boolean
Dim Quality As Long
Dim Height As Long
Dim Width As Long
Dim nHeight As Long
Dim nWidth As Long
DIB.CreateFromPicture mImage
Height = DIB.Height
Width = DIB.Width
If Width > Height Then
fAspect = Height / Width
If Height > 160 Or Width > 120 Then
nWidth = 160
nHeight = 160 * fAspect
End If
Else
fAspect = Width / Height
If Height > 160 Or Width > 120 Then
nWidth = 120 * fAspect
nHeight = 120
End If
End If
Set DIB = DIB.Resample(nHeight, nWidth)
Quality = 30
Do
SaveJPG DIB, tmpFile, Quality
Quality = Quality + 15
'Debug.Print FileLen(tmpFile)
Loop While (FileLen(tmpFile) < 5000) And (Quality < 100)
MakeThumb = tmpFile
End Function
Public Function MakeImage()
Dim Quality As Long
Dim i As Long
DIB.CreateFromPicture mImage
Quality = 100
SaveJPG DIB, tmpFile, Quality
While (FileLen(tmpFile) > 500000)
'Debug.Print FileLen(tmpFile)
SaveJPG DIB, tmpFile, Quality
Quality = Quality - 10
Wend
MakeImage = tmpFile
End Function
Private Sub Class_Terminate()
Set DIB = Nothing
Set mImage = Nothing
On Error Resume Next
Kill tmpFile
On Error GoTo 0
End Sub
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
And here is how it's used:
For Each f In Upload.Files
Recordset.AddNew
If Not Image.LoadImage(Server.MapPath(f.FileName)) Then
Response.Write("Can't load image"
Response.End
End If
Stream.Open
Stream.Type = 1
Stream.LoadFromFile Image.MakeImage
Recordset("Image" = Stream.Read
Stream.LoadFromFile Image.MakeThumb
Recordset("Thumbnail" = Stream.Read
Recordset("ImageID" = Right("000" & Hex(CLng(ImgCount)), 3)
If Not (Request.QueryString("which" = "private" Then
Recordset("UserID" = "0"
Else
Recordset("UserID" = Session("ID"
Recordset("Name" = Left(Upload.Form("name", 250)
Recordset("Description" = Upload.Form("comment"
End If
Recordset.Update
Next
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Here is how the images are regurgitated:
<!-- #include virtual = "common/includes.asp" -->
<%
Recordset.Open "SELECT Images.Thumbnail, Images.Image FROM Images WHERE Images.ID = " & Request.QueryString("id"
Response.ContentType = "image/jpeg"
Response.Clear()
If Request.QueryString("image" = "full" Then
Response.BinaryWrite(Recordset("Image")
Else
Response.BinaryWrite(Recordset("Thumbnail")
End If
Response.Flush()
Response.End()
Recordset.Close
%>
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I know that's a lot to digest at once. I really am at my wits end here, guys. If I add this project to VB, then step through it while displaying the results in a picture box, then I see no abnormalities. Everything works beautifully. Yet as soon as I use it in IIS, I get the link I posted above.
Any ideas? Thanks, guys.
-iNSTA
aim: instar4per
email: instar4per @ hotmail.com
I have an ASP script which accepts an uploaded image ( using the FreeASPUpload class, ), and passes the temporary file's name to a custom component, which is supposed to do the following:
Load the image into an IPicture variable, using LoadPicture.
Convert the image to a DIB and resize.
Use the Intel JPEG library and save the image as a temporary JPEG.
Pass the temporary name back to the ASP script
Open the temporary file as an ADODB Stream, and insert it into a database.
Eventually, pull the data from the database, and pass it as a JPEG file back to the client.
I had all of this working. I modified the math on my resizing code, and suddenly it seems as though the component is now producing images that are no greater than 256 colors. See:
The DIB and JPEG code I am using comes from a project on Planet Source Code, -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Here is my full class code:
Option Explicit
Dim tmpFile As String
Dim mImage As IPicture
Dim DIB As cDIBSection
Private mPath As String
Public Property Let Path(New_Path As String)
Dim i As Long
If Right(New_Path, 1) <> "\" Then New_Path = New_Path & "\"
Randomize
For i = 1 To 20
tmpFile = tmpFile & Chr(65 + Rnd() * 23)
Next
tmpFile = New_Path & tmpFile & ".jpg"
End Property
Public Function LoadImage(sFile) As Boolean
LoadImage = True
On Error Resume Next
Set mImage = LoadPicture(sFile)
If Err.Number Then
LoadImage = False
Exit Function
End If
Set DIB = New cDIBSection
Kill sFile
End Function
Public Function Picture() As IPicture
Set Picture = mImage
End Function
Public Function MakeThumb()
Dim fAspect As Single
Dim bTaller As Boolean
Dim Quality As Long
Dim Height As Long
Dim Width As Long
Dim nHeight As Long
Dim nWidth As Long
DIB.CreateFromPicture mImage
Height = DIB.Height
Width = DIB.Width
If Width > Height Then
fAspect = Height / Width
If Height > 160 Or Width > 120 Then
nWidth = 160
nHeight = 160 * fAspect
End If
Else
fAspect = Width / Height
If Height > 160 Or Width > 120 Then
nWidth = 120 * fAspect
nHeight = 120
End If
End If
Set DIB = DIB.Resample(nHeight, nWidth)
Quality = 30
Do
SaveJPG DIB, tmpFile, Quality
Quality = Quality + 15
'Debug.Print FileLen(tmpFile)
Loop While (FileLen(tmpFile) < 5000) And (Quality < 100)
MakeThumb = tmpFile
End Function
Public Function MakeImage()
Dim Quality As Long
Dim i As Long
DIB.CreateFromPicture mImage
Quality = 100
SaveJPG DIB, tmpFile, Quality
While (FileLen(tmpFile) > 500000)
'Debug.Print FileLen(tmpFile)
SaveJPG DIB, tmpFile, Quality
Quality = Quality - 10
Wend
MakeImage = tmpFile
End Function
Private Sub Class_Terminate()
Set DIB = Nothing
Set mImage = Nothing
On Error Resume Next
Kill tmpFile
On Error GoTo 0
End Sub
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
And here is how it's used:
For Each f In Upload.Files
Recordset.AddNew
If Not Image.LoadImage(Server.MapPath(f.FileName)) Then
Response.Write("Can't load image"
Response.End
End If
Stream.Open
Stream.Type = 1
Stream.LoadFromFile Image.MakeImage
Recordset("Image" = Stream.Read
Stream.LoadFromFile Image.MakeThumb
Recordset("Thumbnail" = Stream.Read
Recordset("ImageID" = Right("000" & Hex(CLng(ImgCount)), 3)
If Not (Request.QueryString("which" = "private" Then
Recordset("UserID" = "0"
Else
Recordset("UserID" = Session("ID"
Recordset("Name" = Left(Upload.Form("name", 250)
Recordset("Description" = Upload.Form("comment"
End If
Recordset.Update
Next
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Here is how the images are regurgitated:
<!-- #include virtual = "common/includes.asp" -->
<%
Recordset.Open "SELECT Images.Thumbnail, Images.Image FROM Images WHERE Images.ID = " & Request.QueryString("id"
Response.ContentType = "image/jpeg"
Response.Clear()
If Request.QueryString("image" = "full" Then
Response.BinaryWrite(Recordset("Image")
Else
Response.BinaryWrite(Recordset("Thumbnail")
End If
Response.Flush()
Response.End()
Recordset.Close
%>
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I know that's a lot to digest at once. I really am at my wits end here, guys. If I add this project to VB, then step through it while displaying the results in a picture box, then I see no abnormalities. Everything works beautifully. Yet as soon as I use it in IIS, I get the link I posted above.
Any ideas? Thanks, guys.
-iNSTA
aim: instar4per
email: instar4per @ hotmail.com