473,398 Members | 2,525 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,398 software developers and data experts.

Image to browser

Hi, noob here

Im using mod_python and apache2 using psp for output of page, i open a
file and resize it with the following code

<%
import Image, util

fields = util.FieldStorage(req)
filename = fields.getlist('src')[0]

path = '/var/www/content/' + filename
size = 128, 128

im = Image.open(path)
print im.resize(size, Image.ANTIALIAS)
%>

so for one, I dont think print does much with psp as far as i can
tell, i cant even do a print 'hello world', it has to be a
req.write('hello world'), but i cant req.write the im.resize. The
manual for im.resize states that its return can go ahead and be
streamed via http but I get a blank page when im expecting to see
image characters dumped to my screen. Python doesn't throw up any
errors. Im not sure where else to look or what to do.

Thanks for any help,
Daniel
Jan 16 '08 #1
3 2352
On Jan 16, 12:16 am, danielatdavesch...@gmail.com wrote:
Hi, noob here

Im using mod_python and apache2 using psp for output of page, i open a
file and resize it with the following code

<%
import Image, util

fields = util.FieldStorage(req)
filename = fields.getlist('src')[0]

path = '/var/www/content/' + filename
size = 128, 128

im = Image.open(path)
print im.resize(size, Image.ANTIALIAS)
%>

so for one, I dont think print does much with psp as far as i can
tell, i cant even do a print 'hello world', it has to be a
req.write('hello world'), but i cant req.write the im.resize. The
manual for im.resize states that its return can go ahead and be
streamed via http but I get a blank page when im expecting to see
image characters dumped to my screen. Python doesn't throw up any
errors. Im not sure where else to look or what to do.

Thanks for any help,
Daniel
its worth noting that ive tried using
print "Content-Type: image/jpeg\n"
before the print im.resize and still no luck
Jan 16 '08 #2
On Jan 16, 1:19 pm, danielatdavesch...@gmail.com wrote:
On Jan 16, 12:16 am, danielatdavesch...@gmail.com wrote:
Im using mod_python and apache2 using psp for output of page, i open a
file and resize it with the following code
<%
import Image, util
fields = util.FieldStorage(req)
filename = fields.getlist('src')[0]
path = '/var/www/content/' + filename
size = 128, 128
im = Image.open(path)
print im.resize(size, Image.ANTIALIAS)
%>
so for one, I dont think print does much with psp as far as i can
tell, i cant even do a print 'hello world', it has to be a
req.write('hello world'), but i cant req.write the im.resize. The
manual for im.resize states that its return can go ahead and be
streamed via http but I get a blank page when im expecting to see
image characters dumped to my screen. Python doesn't throw up any
errors. Im not sure where else to look or what to do.
Thanks for any help,
Daniel

its worth noting that ive tried using
print "Content-Type: image/jpeg\n"
before the print im.resize and still no luck
If you're using the Image module from PIL then im.resize(...) returns
an Image instance.
I have not used mod_python and psp, but try the following:
>>import Image
i = Image.open('server.JPG')
r = i.resize((32,32))
from StringIO import StringIO
b = StringIO()
r.save(b, 'JPEG')
b.seek(0)
req.write("Content-Type: image/jpeg\r\n\r\n")
req.write(b.read())

There's a r.tostring(...) method but I don't see how to make that
return a JPEG stream.

Jan 16 '08 #3
On Jan 16, 12:38 am, Justin Ezequiel <justin.mailingli...@gmail.com>
wrote:
On Jan 16, 1:19 pm, danielatdavesch...@gmail.com wrote:
On Jan 16, 12:16 am, danielatdavesch...@gmail.com wrote:
Im using mod_python and apache2 using psp for output of page, i open a
file and resize it with the following code
<%
import Image, util
fields = util.FieldStorage(req)
filename = fields.getlist('src')[0]
path = '/var/www/content/' + filename
size = 128, 128
im = Image.open(path)
print im.resize(size, Image.ANTIALIAS)
%>
so for one, I dont think print does much with psp as far as i can
tell, i cant even do a print 'hello world', it has to be a
req.write('hello world'), but i cant req.write the im.resize. The
manual for im.resize states that its return can go ahead and be
streamed via http but I get a blank page when im expecting to see
image characters dumped to my screen. Python doesn't throw up any
errors. Im not sure where else to look or what to do.
Thanks for any help,
Daniel
its worth noting that ive tried using
print "Content-Type: image/jpeg\n"
before the print im.resize and still no luck

If you're using the Image module from PIL then im.resize(...) returns
an Image instance.
I have not used mod_python and psp, but try the following:
>import Image
i = Image.open('server.JPG')
r = i.resize((32,32))
from StringIO import StringIO
b = StringIO()
r.save(b, 'JPEG')
b.seek(0)
req.write("Content-Type: image/jpeg\r\n\r\n")
req.write(b.read())

There's a r.tostring(...) method but I don't see how to make that
return a JPEG stream.
brilliant, at least to me anyway, it works as long as i remove the
req.write("content-type...

now i have a lot to look up, i tried something similar to this before
that i found on the web but no luck. i guess whats going on is it gets
saved to this pseudo file thats just a string existing in memory, and
then the pointer gets set to the begining of the string for the
upcoming read() ? i dunno, but something else to learn about. I must
admit i was hoping for something a little more elegant.

Thanks for your help!
Jan 16 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Srinivas Chundi | last post by:
I have to display tif images using .asp page. I have tried to read the image as a binary file and stream it to the browser. The relevant code is as follows. Unfortunately, the display on the...
16
by: Donjuan | last post by:
Hi all I have trouble with tracking whether my image file is loaded. i use DHTML to change my image. HERE is the code: <img name="someimage" src="1.jpg"...
3
by: Kristof Thys | last post by:
Hello, I'm writing a ASP.net webservice wich will visualize an image, generated by another application. The generated image is a char*. I can transform this to a String*, but I want to view it...
3
by: ACaunter | last post by:
Hi there, I was wondering if there was a way to crop a peice of an ASP.Net Image, allowing the user to zoom in on only a section of the picture?? any help would be appreciated!! thanks --...
14
by: Rudy | last post by:
Hello all! I been trying to get a handle with Images. I have learned alot from the fine people here. So, I also learned that thumbnail images look terrible taken from a digital cam. I know why...
4
by: Jake | last post by:
Does cookieless session state (with the sessionid embedded into the url) interfere with the browser's retrieval of cached images from one session to the next? Does the sessionid embedded into the...
10
by: FX | last post by:
I wanna publish a script on my site which allows me to hide image source. i have rough idea abt it. i`ll point src to some php page like: <img src="image.php"> & in tht php wat exactly shud be...
6
by: Mark Denardo | last post by:
I created a Web Image "<asp:Image ID="Image1" ..." that my code behind set to a certain image file say image1.jpg =Image1.ImageUrl = "<rel_path>/image1.jpg"; which set the image ok, but then I...
8
by: Edward Diener | last post by:
Is there a way in Javascript, or perhaps in HTML, to force a browser to re-render an image on an HTML page after a round-trip between the client and the server ? In my particular case, the image...
3
by: helraizer1 | last post by:
Hey folks, I have made an image-based shoutbox and now users can view older and newer message on the shoutbox depending on the $_GET - pagination - that works. However, since it's image based and...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
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,...
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
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...
0
agi2029
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,...

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.