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

Xavier Morel xavier.morel at masklinn.net
Fri Jan 20 05:57:48 EST 2006


Steve Holden wrote:
> 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

Well, some people have been crazy enough lately to generate more or less 
imageless bar graphs though, see Eric Meyer's "Bar Graphs with Style" 
(http://meyerweb.com/eric/thoughts/2005/12/20/bar-graphs-with-style/) 
for more informations on the subject 
(http://meyerweb.com/eric/css/edge/bargraph/demo.html for a demo)



More information about the Python-list mailing list