Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Crop Binary Image ASP

Posted on 2010-08-16
7
Medium Priority
?
718 Views
Last Modified: 2012-05-10
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?
0
Comment
Question by:synergiq
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 28

Expert Comment

by:sybe
ID: 33449163
For classic ASP, You need a third party component to do this. Like ASPJPEG (http://www.aspjpeg.com/index.html). I don't know of any non-commercial third party component which can do this.

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.
0
 
LVL 2

Author Comment

by:synergiq
ID: 33453123
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.
0
 
LVL 28

Expert Comment

by:sybe
ID: 33453163
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
0
Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

 
LVL 2

Author Comment

by:synergiq
ID: 33453237
Could you give me an example of how I would do that?
0
 
LVL 28

Accepted Solution

by:
sybe earned 2000 total points
ID: 33453429
This is the basic code. Of course you might to do things in a loop, and with Option Explicit you need to DIM the variables.


Set oStream = Server.CreateObject("ADODB.Stream")
oStream.Type = 1 ' adTypeBinary
oStream.LoadFromFile "c:\files\image_1.jpg"

Set oRS = Server.CreateObject("ADODB.RecordSet")
oRS.Open "SELECT fieldname FROM mytable WHERE id = 967",  MyConnection, 1, 3
oRS("fieldname").AppendChunk oStream.Read
oRS.Update
oRS.Close

Open in new window

0
 
LVL 2

Author Comment

by:synergiq
ID: 33453580
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.
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

Open in new window

0
 
LVL 2

Author Comment

by:synergiq
ID: 33453628
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

Open in new window

0

Featured Post

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question