I have a database setup for my web site that stores images.
the code I have to use in an IMG tag is:
Set oConn2 = Server.CreateObject("ADODB.Connection")
Set oRS2 = Server.CreateObject("ADODB.Recordset")
oConn2.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("/database/database.mdb")
strSQL="SELECT * FROM " & Request("db") & " where id = " & Request("id")
oRS2.Open strSQL, oConn2, 3, 1
Response.ContentType = "application/octet-stream"
Response.AddHeader "Content-Disposition", "attachment;filename=" & Trim(oRS2(FileName))
Response.AddHeader "Content-Length", oRS2(FileSize)
Response.BinaryWrite oRS2(PicName)
oRS2.Close
oConn2.Close
Set oRS2 = Nothing
Set oConn2 = Nothing
The issue is, i would like to use GflAx to resize these images when they are shown on the web page.
I have looked at using the following:
pn = oRS2(PicName)
img.enablelzw= True
img.ReceiveBinary PN
But i get an error:
GflAx.GflAx.1 error '80004005'
Bad parameters : 16396
PLEASE help, I do not want to have to store the images on the server in a directory, I like having them as part of the database.
ASP & Database
Moderators: XnTriq, helmut, xnview
-
- Posts: 26
- Joined: Wed Mar 09, 2005 7:44 pm
Well, I hope by now you've figured out why no one has yet responded. Putting images in a database is a might poor way of doing things, and if you haven't paid attention to the advice I know you've read already, why would we think you'll listen to what we have to say.
Anyway, here's a nice bit of annotated ASP code from which you may see the way out of your problem:
Anyway, here's a nice bit of annotated ASP code from which you may see the way out of your problem:
Code: Select all
<%
'image.asp
'Code by Bruce Wilson, UVSC
'This code is called in a <img> tag as follows:
'<img src="image.asp?f=filename&c=txt&x=n&y=n&w=n&h=n&dh=n&dw=n"> where n are integers
set GflAx = Server.CreateObject("GflAx.GflAx")
GflAx.LoadBitmap Request.QueryString("f") 'f=path to the file, came from the database
c = request.querystring("c") 'name of copyright holder
x = Request.QueryString("x")
y = Request.QueryString("y")
'x and y define the top left corner of the section of the image to be viewed.
w = clng(Request.QueryString("w")) 'the width of the crop. A long variable is needed for the if-then
h = clng(Request.QueryString("h")) 'the height of the crop
dh = Request.QueryString("dh") 'DisplayHeight, the height of the image to be delivered
dw = Request.QueryString("dw") 'displayWidth, the width of the image to be delivered
fw = GflAx.width 'full image width
fh = GflAx.height 'full image height
m = fw/w 'magnification factor
s=30 'sharpening factor, scales for different levels of magnification; more sharpening is used
if m>150 then s=35
if m>300 then s=50
'don't crop if the entire image is requested:
if (w<fw) OR (h<fh) then GflAx.Crop x, y, w, h
GflAx.Resize dw, dh
GflAx.Sharpen s
if c<>"" then
With GflAx
.FontSize = 24
.FontName = "Georgia"
.FontBold = True
.FontItalic = True
.TextOut c, 15, dh-24, RGB(255,255,255)' white shadow
.TextOut c, 14, dh-26, RGB(0, 64, 0) 'dark green text
end With
End If
'Gflax.EnableLZW = True 'only needed for GIF images
GflAx.SaveFormat = 1 '1=JPEG, 2=GIF, 3=PNG, 4=BMP, 5=TIFF
GflAx.SaveJPEGProgressive = TRUE
GflAx.SaveJPEGQuality= 85 'this can be raised to 100 for better image quality at the expense of bandwidth
Response.ContentType = "image/jpeg"
Response.BinaryWrite GflAx.SendBinary
set GflAx = nothing
%>
-
- Posts: 26
- Joined: Wed Mar 09, 2005 7:44 pm
See this code in action: http://herbarium.uvsc.edu/Virtual/viewe ... 5312s2.jpg
Generating images on-the-fly over and over again is bad too.b.e.wilson wrote:Well, I hope by now you've figured out why no one has yet responded. Putting images in a database is a might poor way of doing things, and if you haven't paid attention to the advice I know you've read already, why would we think you'll listen to what we have to say.
I agree that serving images from a database is bad because of
- overhead (ASP, DB queries),
- bypassing OS optimizations where available (e.g. sendfile, disk caches, server-internal optimizations)
- and usually the incorrect/imcomplete implementation (like yours):
- missing cache headers/handling of those. (performed by the server when it comes to static files). Think "304 - Not modified" :p
- missing Filename, Size and so on.
You both, what do you think your server will do when there are several hundred hits/sec?
It will choke or even get completely unresponsive.
Furthermore, RomanDA, why is there a manual?
GetBlob/SetBlob? How about those?
-
- Posts: 26
- Joined: Wed Mar 09, 2005 7:44 pm
Well, my servere will choke. Take a look at the paqe I posted and see if you want to pre-make and cache all the versions that might be called for.
We push imaging to different processes right now anticipating the move to different servers.
And take another look at the page I posted and say when we might anticipate 100 hits/sec.
We push imaging to different processes right now anticipating the move to different servers.
And take another look at the page I posted and say when we might anticipate 100 hits/sec.