471,344 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,344 software developers and data experts.

Binary blobs to jpeg

Hello All.
I'm trying to create jpegs out of data that is stored in a binary blob
format in an RDBMS (MS Access). I've tried writing the jpeg directly:

while not rs.EOF:
op = file(imgdir + "\\" + pic,"w")
print >op, rs.Fields[3].Value
##where rs.Fields[3].Value is the data in the blob from Access.

When I try to write out this file, the jpeg doesn't turn out.
Strangely, some of the colors partially render. You can see some
outlines and backgrounds, but the full picture doesn't show. Most
jpegs, however, show nothing (in an windows preview).

I then tried opening the image with PIL.Image, with something like
this:

cmd.CommandText = sql
rs=cmd.Execute()[0]
while not rs.EOF:
im = Image.open(StringIO.StringIO(rs.Fields[3].Value))
im.save("c:/projects/temp.jpg", 'JPEG', quality=90,progressive=1)

This is the error I get, I believe at the Image.open() call:
Traceback (most recent call last):
File "<string>", line 97, in run
File "C:\Python25\Lib\bdb.py", line 366, in run
exec cmd in globals, locals
File "C:\Projects\scripts\main.py", line 25, in <module>
xdb.doImageTbl(db)
File "C:\Projects\scripts\thunder.py", line 86, in doImageTbl
im = Image.open(StringIO.StringIO(rs.Fields[3].Value))
File "C:\Python25\lib\site-packages\PIL\Image.py", line 1916, in
open
raise IOError("cannot identify image file")
IOError: cannot identify image file
For a little further information, I was able to accomplish this task
in C#/.Net. A direct write to a file stream produced the exact jpeg
image. So I know the data is not corrupt. I would like to avoid using
the C#/.Net solution if possible.

Any ideas what I'm doing wrong? Any help would be greatly appreciated.

BTW, I'm using Python 2.5 and PIL 1.1.6 on a WinXp box.

Thanks,
jeh

Jul 16 '07 #1
5 6165
On Mon, 2007-07-16 at 18:57 +0000, ja*********@gmail.com wrote:
Hello All.
I'm trying to create jpegs out of data that is stored in a binary blob
format in an RDBMS (MS Access). I've tried writing the jpeg directly:

while not rs.EOF:
op = file(imgdir + "\\" + pic,"w")
print >op, rs.Fields[3].Value
##where rs.Fields[3].Value is the data in the blob from Access.

When I try to write out this file, the jpeg doesn't turn out.
Have you tried to open the file in "wb" mode?

HTH,

--
Carsten Haese
http://informixdb.sourceforge.net
Jul 16 '07 #2
Have you tried to open the file in "wb" mode?
>
HTH,

--
Carsten Haesehttp://informixdb.sourceforge.net
The data is coming from a record set selection from the Access
database. I guess I could write the data to a temp file and open that
file handle with the "wb" mode. But, no, I haven't tried that.

jeh

Jul 16 '07 #3
On 2007-07-16, ja*********@gmail.com <ja*********@gmail.comwrote:
>Have you tried to open the file in "wb" mode?

The data is coming from a record set selection from the Access
database. I guess I could write the data to a temp file and
open that file handle with the "wb" mode. But, no, I haven't
tried that.
I think you missed the point.

When you want to write the binary data to a file, you must open
the destination file using "wb" mode. It's binary data, not
text data, so you have to open the output file in binary mode.

--
Grant Edwards grante Yow! Is my fallout shelter
at termite proof?
visi.com
Jul 16 '07 #4
On Jul 16, 3:23 pm, Grant Edwards <gra...@visi.comwrote:
On 2007-07-16, jayharva...@gmail.com <jayharva...@gmail.comwrote:
Have you tried to open the file in "wb" mode?
The data is coming from a record set selection from the Access
database. I guess I could write the data to a temp file and
open that file handle with the "wb" mode. But, no, I haven't
tried that.

I think you missed the point.

When you want to write the binary data to a file, you must open
the destination file using "wb" mode. It's binary data, not
text data, so you have to open the output file in binary mode.

--
Grant Edwards grante Yow! Is my fallout shelter
at termite proof?
visi.com
I did miss the point. I will give that a shot. Thanks Carsten and Grant

Jul 16 '07 #5
On Jul 16, 7:54 pm, jayharv...@gmail.com wrote:
On Jul 16, 3:23 pm, Grant Edwards <gra...@visi.comwrote:


On 2007-07-16, jayharva...@gmail.com <jayharva...@gmail.comwrote:
>Have you tried to open the file in "wb" mode?
The data is coming from a record set selection from the Access
database. I guess I could write the data to a temp file and
open that file handle with the "wb" mode. But, no, I haven't
tried that.
I think you missed the point.
When you want to write the binary data to a file, you must open
the destination file using "wb" mode. It's binary data, not
text data, so you have to open the output file in binary mode.
--
Grant Edwards grante Yow! Is my fallout shelter
at termite proof?
visi.com

I did miss the point. I will give that a shot. Thanks Carsten and Grant- Hide quoted text -

- Show quoted text -
This worked fantastically. Thanks!

Jul 17 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Phil Palmieri | last post: by
3 posts views Thread by David Stockwell | last post: by
5 posts views Thread by Blaktyger | last post: by
7 posts views Thread by Fernando Chilvarguer | last post: by
3 posts views Thread by Josema | last post: by
5 posts views Thread by AlexCDM | last post: by
2 posts views Thread by Lucas Cowald | last post: by
4 posts views Thread by Beginner | last post: by
reply views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.