synergiq
asked on
Crop Binary Image ASP
I have some images saved in a database as binary. I need to crop the images and re-save them as binary into the database.
How can I do this with classic ASP?
How can I do this with classic ASP?
ASKER
Ok. So using ASPJPEG, I've managed to get the image from the DB, crop it to the correct dimensions but now I need to put it back into the DB. Trying to just do an update doesn't work, do I need to do something/convert it to something first?
I'm using a Sybase database if that means anything.
I'm using a Sybase database if that means anything.
How are you trying to do that?
I'd read the binary of the image into a ADODB.Stream and from that update a recordset, using the AppendChunk method:
http://www.w3schools.com/ado/met_para_appendchunk.asp
I'd read the binary of the image into a ADODB.Stream and from that update a recordset, using the AppendChunk method:
http://www.w3schools.com/ado/met_para_appendchunk.asp
ASKER
Could you give me an example of how I would do that?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I don't have access to the actual image to stream though, only the Jpeg.Binary I get from ASPJPEG.
The code below gets the image from the DB (as binary), opens it with ASPJPEG and crops it. Now I just need to put it back in the DB in place of the old one.
The code below gets the image from the DB (as binary), opens it with ASPJPEG and crops it. Now I just need to put it back in the DB in place of the old one.
Set GetImg_cmd = Server.CreateObject ("ADODB.Command")
GetImg_cmd.ActiveConnection = MM_MobliqConn_STRING
GetImg_cmd.CommandText = "select image_field from table where image_id = '1234'"
GetImg_cmd.Prepared = true
Set GetImg = GetImg_cmd.Execute
GetImg_numRows = 0
Set Jpeg = Server.CreateObject("Persits.Jpeg")
Jpeg.OpenBinary(GetImg("image_field").value)
Jpeg.Crop 0, 0, 80, 60
GetImg.close()
set GetImg= nothing
ASKER
I've just cracked it. Thanks for the help!
Set rs = Server.CreateObject("adodb.recordset")
rs.Open "select image_field from table where fimage_id = '1234'", myConn, 1, 3
rs("image_field").AppendChunk Jpeg.Binary
rs.Update
rs.Close
Alternatively there are some freeware desktop applications which can crop in batch. You could write a vbscript (.vbs) to pull the images from the database to hd, use that tool to batch-crop them and then another vbscript to put the cropped binaries into the database.
But that is probably not going to function live in a web-application.