473,385 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 6369
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Phil Palmieri | last post by:
Im using md5 to encrypt and decrypt plain text, this works fine... When i try to run the same function on a binary file, it does not decrypt correctly. Is there a way to encrypt binary files...
3
by: David Stockwell | last post by:
Hi, I'd like to read the contents of a file into memory. The problem is that this file is binary. I then want to store the whole thing in memory to a database as a blob. I have no problem...
5
by: Blaktyger | last post by:
How can this be done? Images are stored in a LONGBLOB field. When I try to display them, it prints out the binary data as it is... Thank you
7
by: Fernando Chilvarguer | last post by:
I'm having problems with a simple binary write. The page is just supposed to write a JPEG back to the browser but the image does not display (the "X" image shows). Any help is appreciated. Here's...
3
by: Josema | last post by:
Hi to all, I have stored in a database some binary files (pdfs, and gif images), i would like to know how could i show it, in internet explorer when a person enters for instance in a textbox the...
5
by: AlexCDM | last post by:
Greetings; I'm a (young) .NET developer and I have this problem: I'm building an application (with C#) that creates PDF files. To display a JPEG image within the PDF I need to copy the data from...
2
by: Lucas Cowald | last post by:
Hi, Using ASP and VBScript. How to convert JPEG image into a binary data? Is it possible with a command from ASP / VBScript without having to put it into a database first? I want to take the...
4
by: Beginner | last post by:
How do I convert JPEG images to binary files in ASP.NET? Please advice. Thanks.
1
by: htres | last post by:
Hello, I'm new to programming and C#, so please bear with my ignorance! I need to extract jpeg images and header data from a binary file. The binary file is formatted with several fixed...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.