[Image-SIG] Getting information from Flash to PIL
Gregor Kopka
gregor at kopka.net
Fri Dec 12 02:37:53 CET 2008
Hi Frederico,
the code you took to start with isn't that bad, but it's originally used
for a doodling demo which has a uniform white background (which is
something that you won't have) so the protocol used will inflate the
uncompressed image data you have by a factor of at least 3.5 !
Since you POST anyway maybe better use a binary format which:
- gets rid of the useless (at least for sending webcam images)
pseudo-compression (removing a uniform background color - which you
won't have) scheme
- avoids encoding the data as an ASCII string (which inflates the size
of the data by at least 3.5 times)
for better performance / less data to transfer?
The easiest way would be to put something in the flash applet which
outputs something that can be directly fed to Image.fromstring or
Image.frombuffer.
After getting that to work you can then add some sort of real
compression, here's some fodder for you to get started:
http://www.razorberry.com/blog/archives/2004/08/22/lzw-compression-methods-in-as2/
http://newmovieclip.wordpress.com/2006/05/15/image-compression-possibilities-in-flash-8/
The problem you will have is that LZW isn't that good performing (in
terms of compression rate) on stuff like video images... so better code
it in a way that you can plug-in another, better suited compression
scheme later.
But it'll be better than encoding it in ASCII for sure :)
Regards,
Gregor
Frederico Leonardo schrieb:
> Hi all,
>
> I've only recently started using Python via Django and so far I'm loving it.
> I have a question that hopefully someone might be able to answer. I've
> scouted the internet looking for this but can't manage to find the
> right example.
>
> I'm creating an e-card application in Django. Some of the e-cards are
> SWF with a script that reads your webcam and then produces a new card
> with the webcam information. Flash is working fine and it's sending me
> variables to construct the new image. I can already get the width and
> height:
>
> card_width = int(request.POST.get('width',''))
> card_height = int(request.POST.get('height',''))
>
> But I have no idea how to convert the rest of the information into an
> image, let alone draw and save it.
>
> This is what Flash is sending me via 'POST':
>
> Variable: px19
> Value: u',,,,,,,,,,,,,,,,,,,,,,,,,,,,,eeffff,abcae7,8baece,6c90b0,6b8faf,698bae,6789ae,(...)
>
> It repeats this for every px# and is also sending me rows and cols,
> besides the width and height. Those values are hex and I suppose that
> they correspond to the rows, each color being 1 pixel per column.
> I came across this technique here:
> http://www.sephiroth.it/tutorials/flashPHP/print_screen/page002.php
> But alas, it's a PHP script, that I would very much love to reproduce using PIL.
>
> How can I grab that information into an array and then have PIL
> convert it into a JPG that I can save on the server. Any ideas?
>
> Thank you!
>
> — Frederico
> _______________________________________________
> Image-SIG maillist - Image-SIG at python.org
> http://mail.python.org/mailman/listinfo/image-sig
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gregor.vcf
Type: text/x-vcard
Size: 314 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/image-sig/attachments/20081212/8e95ac57/attachment.vcf>
More information about the Image-SIG
mailing list