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 5 5036
"Blaktyger" <bl*******@hotm ail.com> wrote in message
news:c9******** *************** ***@posting.goo gle.com... 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
You could get PIL at http://www.pythonware.com/products/pil/
and try the Image.fromstrin g() function.
Tom
Blaktyger wrote: 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...
Display where? On local screen, in a webbrowser?
Assuming the first one, see post by Tom.
Assuming the second one (you're writing a cgi,mod_python. .. program),
did you set the content-type in the http header correctly?
Benjamin Niemann <b.*******@bett ernet.de> wrote in message news:<cf******* ***@online.de>. .. Blaktyger wrote:
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... Display where? On local screen, in a webbrowser? Assuming the first one, see post by Tom. Assuming the second one (you're writing a cgi,mod_python. .. program), did you set the content-type in the http header correctly?
In a webbrowser...
this is my code...
#!/usr/bin/python2.3
print 'Content-Type:image/jpeg\n\n'
import blakHtml, sys
sys.stderr = sys.stdout
import MySQLdb
import urllib
import cgi
import time
prevPg=blakHtml .HTMLDocument()
newConnection=M ySQLdb.connect( host='localhost ', user='blaktyger ', \
passwd='linux4e ver', db='photoFamill e')
curseur=newConn ection.cursor()
sqlCmdFr="""SEL ECT * FROM photo"""
curseur.execute (sqlCmdFr)
resultats = curseur.fetchal l()
p=0
for val in resultats:
p=p+1
#print '<img src=" ' + val[5]+ ' " ' +' >' THIS DOES NOT WORK
print val[5]
newConnection.c lose()
I know there is no HTML code but this is just a test...
>>>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... Display where? On local screen, in a webbrowser? Assuming the first one, see post by Tom. Assuming the second one (you're writing a cgi,mod_python. .. program), did you set the content-type in the http header correctly?
In a webbrowser... this is my code...
#!/usr/bin/python2.3
print 'Content-Type:image/jpeg\n\n'
You must use '\r\n' to terminate header lines. I'm not really sure, but
maybe there should also be a spacing between ':' and 'image/jpeg'...
If you are using e.g. FireFox as a browser, you can user 'View Page
Info' to see, if the browser correctly understands, what you are trying
to tell it ('Type' should say 'image/jpeg').
import blakHtml, sys sys.stderr = sys.stdout import MySQLdb import urllib import cgi import time prevPg=blakHtml .HTMLDocument() newConnection=M ySQLdb.connect( host='localhost ', user='blaktyger ', \ passwd='linux4e ver', db='photoFamill e') curseur=newConn ection.cursor()
sqlCmdFr="""SEL ECT * FROM photo""" curseur.execute (sqlCmdFr) resultats = curseur.fetchal l() p=0 for val in resultats: p=p+1 #print '<img src=" ' + val[5]+ ' " ' +' >' THIS DOES NOT WORK print val[5] newConnection.c lose() I know there is no HTML code but this is just a test...
val[5] contains the raw image data (not a path), correct? Does 'photo'
contains more than one image? Concatenating several images into one
bytestream, is definitly not what you want.
Benjamin Niemann <b.*******@bett ernet.de> wrote in message news:<cf******* ***@online.de>. .. 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...
Display where? On local screen, in a webbrowser? Assuming the first one, see post by Tom. Assuming the second one (you're writing a cgi,mod_python. .. program), did you set the content-type in the http header correctly?
In a webbrowser... this is my code...
#!/usr/bin/python2.3
print 'Content-Type:image/jpeg\n\n'
You must use '\r\n' to terminate header lines. I'm not really sure, but maybe there should also be a spacing between ':' and 'image/jpeg'... If you are using e.g. FireFox as a browser, you can user 'View Page Info' to see, if the browser correctly understands, what you are trying to tell it ('Type' should say 'image/jpeg').
import blakHtml, sys sys.stderr = sys.stdout import MySQLdb import urllib import cgi import time prevPg=blakHtml .HTMLDocument() newConnection=M ySQLdb.connect( host='localhost ', user='blaktyger ', \ passwd='****', db='photoFamill e') curseur=newConn ection.cursor()
sqlCmdFr="""SEL ECT * FROM photo""" curseur.execute (sqlCmdFr) resultats = curseur.fetchal l() p=0 for val in resultats: p=p+1 #print '<img src=" ' + val[5]+ ' " ' +' >' THIS DOES NOT WORK print val[5] newConnection.c lose() I know there is no HTML code but this is just a test... val[5] contains the raw image data (not a path), correct? Does 'photo' contains more than one image? Concatenating several images into one bytestream, is definitly not what you want.
val[5] contains only one image but I saw that when printing out val[5]
is that the binary data is in a array. So this i what I did...
import array
[same code as before except for this... ]
print 'Content-Type: image/jpeg\r\n'
[...]
for val in resultats:
p=p+1
img=''
t=''
# t is an array object. the tostring() argument extracts the
binary data
t=val[5].tostring()
print t
and it works!
Thanks for your help Ben! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Srdjan Pejic |
last post by:
Hello,
I have a problem that I have not been able to solve, even after
searching the web. I have stored couple of images in the MySQL database
and I am trying to get them displayed on a web page with PHP.
Now, before we go any further, I want to make it clear that I am very
aware of the current debate about storing images in the database. I
understand both sides, however this is something I want to do for fun,
as well as good learning.
|
by: Dave Posh |
last post by:
I seem to be having a problem displaying time stored in mysql. The
format stored in the database is 13:15:05. The database data type is
time. I'm using asp vbscript and sql to retrieve the time store in
the database. However asp recognizes the data type as date and
displays the date instead of the time. If I change the data type in
mysql to varchar then asp will display the time correctly, but I
cannot do it this way. I want to be able...
|
by: Vinay |
last post by:
Hi All:
I have a small application that stores images either in the database or as
files (depending on the user preference). I'm in the process of providing a
web interface to this application.
1. If the images are stored in the DB then, every an image is requested, it
will need to be pulled out and a temp file created and then displayed? What
is the best way to do this?
|
by: Matt |
last post by:
Hi
I'm have difficulty displaying images that are stored in a MySQL database.
I've tried using the odbc.net provider, the ByteFX provider and the
MySQLDriverCS one but can't seem to get the image to display on the screen.
I've tried searching on the net but can only find examples on how to do it
on SQL Server and havent had any luck converting them to work with MySQL.
I thought I had to put the data into a byte variable then use
|
by: Jim |
last post by:
I am trying to display images that are stored in a database, and I am using a
repeater control. What I still use the Response.BinaryWrite method with a
binding expression, if so, what with the code look like?
| |
by: CLEAR-RCIC |
last post by:
I have several images i want to display in an ASP.Net application. The
images are being passed to me in binary format from another application. Is
there a good way to write them directly to an HMTL page without having to
save them to the server and create a URL to the virtual directory?
FYI: I currently am doing this with just single images. I do a
Response.BinaryWrite(byte) to display the one image. The advantage is that I
never...
|
by: eholz1 |
last post by:
Hello Members,
I am setting up a photo website. I have decided to use PHP and MySQL.
I can load jpeg files into the table (medium blob, or even longtext)
and get the image(s) to display without a problem. I am using
chunk_split(data) and the base64_encode and base64_decode on the files.
I do a select from the database, and then echo the image (with
header(Content Type: image/jpeg)
and the decoded image displays fine. Yes, I have...
|
by: CodedSammy |
last post by:
Hello.
I am developing a solution in Visual Basic which will require me to display images stored in a disk files along with the content of my MySQL Database using the filenames of the images to link them to database records. Please help on how I can go about this.
Thanks.
|
by: redpears007 |
last post by:
Hi Again,
Throwing this one out to you again as i am not getting anywhere and
can find little to no information out there.
I am currently displaying images (Jpegs) in access via the routine set
up in the article http://support.microsoft.com/kb/285820/en-us. It
works fine if the image is under 1000x1000 pixels. It is set up so
the user can double click to open the image in its host application.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |