473,657 Members | 3,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.FieldStora ge(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('hell o 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 2369
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.FieldStora ge(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('hell o 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.FieldStora ge(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('hell o 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('ser ver.JPG')
r = i.resize((32,32 ))
from StringIO import StringIO
b = StringIO()
r.save(b, 'JPEG')
b.seek(0)
req.write("Co ntent-Type: image/jpeg\r\n\r\n")
req.write(b.r ead())

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.mailing li...@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.FieldStora ge(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('hell o 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('ser ver.JPG')
r = i.resize((32,32 ))
from StringIO import StringIO
b = StringIO()
r.save(b, 'JPEG')
b.seek(0)
req.write("Con tent-Type: image/jpeg\r\n\r\n")
req.write(b.re ad())

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("cont ent-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
11761
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 browser is a lot of gobledygook. How can I ensure that the image displays correctly in the browser? Dim objStream Dim FilImage, FolImage, strFilImage Dim adTypeBinary adTypeBinary = 1 Set objStream = Server.CreateObject("ADODB.Stream")
16
6190
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" onclick="document.all.someimage.src='someimage.jpg"> but how can i determine whether "someimage.jpg" is loaded? and can i get the download percent of a file? Thanks in advance
3
1721
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 as an image in my browser. Is this possible, and how should I do this? thx,
3
8458
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 -- AdamPC@hotmail.com
14
2780
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 they look bad. So what is the best way to resize an image. I'm not too concerned about size, but I guess I would like to compress it on the upload. Any thoughts?
4
2685
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 url effectively limit client-side image caching to the lifetime of the session? Thanks Jake
10
31692
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 done so tht user doesnt come to know the real source location of image file upon clicking its properties. I've seen websites doing this. can somebody post the script for it? Thanx in advance
6
4991
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 replaced that image file with another image file and gave it the same name "image1.jpg". But my web app when it loads the image when I run the page still shows the original picture that I deleted and replaced with the new one, even though I...
8
4048
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 is changing on the server although the URL for it remains the same, but the browser is still displaying the old image from its cache rather than the new image from its URL location.
3
1618
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 can be linked in forums etc. on the Internet I only want it to save the gif image if $page == 1, so the newest shouts are saved onto the image. Yet the users can still view the other messages on site without it changing the saved gif image. What...
0
8384
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, 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...
0
8820
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, 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...
1
8499
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8601
tracyyun
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...
0
4150
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...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.