Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 28th, 2006, 11:35 PM
Ray Schumacher
Guest
 
Posts: n/a
Default how to serve image files without disk use?

I'm trying to make a small camera server using VideoCapture.py and
socket. I needed to construct a complete image file with headers etc
for a browser to recognize it, but I couldn't find a combination of
StringIO and wx image methods to avoid disk saves, without PIL.

If I save a temp.jpg file to disk I can serve the image easily:
....
self.cam = VideoCapture.Device(devnum=0, showVideoWindow=0)
buff, width, height = self.cam.dev.getbuffer()
im = wx.EmptyImage(width, height)
im.SetData(buff)
im.Mirror().SaveFile('temp.jpg', wx.BITMAP_TYPE_JPEG)
....
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
while 1:
data = conn.recv(1024)
if data[:3] == 'GET':
conn.send("HTTP/1.0 200 OK"+"\015\012")
conn.send("Server: RJS_video/0.0.1"+"\015\012")
conn.send("Content-type: image/bmp"+"\015\012")
conn.send("Content-Length: "+str(352*288*3+256)+"\015\012")
conn.send("\015\012")
fh = file('temp.jpg', 'rb')
conn.send(fh.read())
fh.close()
else: break

But, how can I avoid disk writes? wx's *.SaveFile() needs a string
file name (no objects).
I'm going to investigate PIL's im.save(), as it appears to allow
file-objects.


Ray

  #2  
Old December 29th, 2006, 08:25 AM
Tom Plunket
Guest
 
Posts: n/a
Default Re: how to serve image files without disk use?

Ray Schumacher wrote:
Quote:
But, how can I avoid disk writes? wx's *.SaveFile() needs a string
file name (no objects).
I'm going to investigate PIL's im.save(), as it appears to allow
file-objects.
Take a look at the img2*.py files in wx.tools. They're sorta sketchy
imo, but they do the trick. encode_bitmaps.py, with the wx demo app, is
used to generate all of the bitmap data that's in Python files embedded
into the app, and following the chain of logic from there might yield
you something interesting.

Mind, I haven't tried it myself, but it's where I'd start looking.

Good luck,
-tom!

--
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles