How to generate graphics dynamically on the web using Python CGI script?

Christophe chris.cavalaria at free.fr
Mon Jan 23 13:50:47 CET 2006


Steve Holden a écrit :
> Debashis Dey wrote:
> 
>> Hello,
>>  
>> I have a python CGI program. I would like to show a graph within a 
>> HTML plage. I would like to dynamically generate the graph using the 
>> python CGI script on the web server side and send it to the browser.
>>  
>> My question is how can I do this in python? Is there a free tool to do 
>> this? Can someone please send me some simple python code to draw 
>> simple graphics within HTML (e.g. draw a line or a circle).
>>  
> 
> Unfortunately HTML does not include graphics facilities, simply the 
> ability to refer to graphical resources.
> 
> The typical way to include a created graphic would be:
> 
>  1. Create a (.png, .jpg, .gif) file showing the
>     image you want
> 
>  2. Store it in a temporary file whose name will be
>     unique to the current session
> 
>  3. Generate an HTML response including an <IMG ...>
>     tag referring to the newly created graphic
> 
> Step 1, which is what you seem to be asking about, can be handled by a 
> number of packages, perhaps the best-known of which is PIL, the Python 
> Imaging Library - see
> 
>   http://www.pythonware.com/products/pil/
> 
> This is open source, and available at no cost. There's a wealth of 
> information on how to use it on the web, and many regular readers of 
> this group are skilled with it!
> 
> regards
>  Steve

Actually, there's a way to store an image inline in the HTML <img> tag.

Here's an example usage : 
http://www.sencer.de/article/1135/how-to-inline-your-sparklinesimages-in-php-with-data-uris



More information about the Python-list mailing list