[OpenMadrigal-developers] script to convert postscript plots to png and jpeg

William Rideout brideout at haystack.mit.edu
Fri Apr 23 11:19:20 EDT 2004


Christian Haggstrom wrote:

> The plots and images found among the experiments is often in Postscript
> format, but it's easier to display them as PNG or JPG in a web browser.
> Therefore I have made a python script to convert them on-the-fly using
> ghostscript.
> 

Christian,

This is an excellent piece of work and a good addition to Madrigal, so I'd like 
to add it as a part of the Madrigal distribution.  I do have a few suggestions 
to make it more consistent with Madrigal.  If you'd like to make the following 
changes, that would be great; otherwise I can do them - let me know what you want.

1.  Since the core functionality of this code - converting graphic formats on 
the fly and displaying links on the web - is something that could be used 
elsewhere, I'd like to put all that generic functionality into a module in the 
madpy API instead of in an executable.  I'd like to create a module called 
something like graphicConverter.py in madrigal/ui, and have it contain all the 
functionality you provide as classes.  This way python can access this 
functionality without kicking off a separate process.

2. You can then create a very small executable that imports this new class, 
parses the command line, and calls the needed methods.  This method should be 
created in the standard place for python executables: source/madpy/scripts/bin.

3.  Madrigal stores all executables it calls in $MADROOT/bin, so during 
installation your new executable would be put there.  To call it from a tcl cgi 
script, you'd just execute "<madroot>/bin/getMadplot.py".  This would avoid the 
awkwardness of putting an executable in the CGI directory.  See the tcl cgi 
scripts for the standard way they find the value of $MADROOT: [madrigal cget 
-madroot].  (Note you can't use getenv - the web server often does not have env 
parameters set that users do - see my next comment).

4.  How to handle the following problem in the standard Madrigal way:

> +# These seems to be neccesary on www.eiscat.com... ugly
> +os.environ['GS_FONTPATH'] = os.environ.get('GS_FONTPATH', '.')+':/usr/openwin/lib/X11/fonts/Type1/outline'
> +os.environ['GS_LIB'] = os.environ.get('GS_LIB', '.')+':/usr/openwin/lib/X11/fonts/Type1:/usr/openwin/lib/X11/fonts/Type3:/usr/local/share/ghostscript/8.00/lib/fonts'
> +

Web servers often don't have env variables set (which is why it works for you 
without this line, but not the web server), so Madrigal uses the madrigal.cfg 
file to deal with this issue.  I'll add two new parameters to madrigal.cfg: 
MAD_GS_FONTPATH and MAD_GS_LIB.  So your class should have the lines:

os.environ['GS_FONTPATH'] = 'MAD_GS_FONTPATH'
os.environ['GS_LIB'] = 'MAD_GS_LIB'

During installation MAD_GS_FONTPATH and MAD_GS_LIB will be replaced by whatever 
values the system admin set in the madrigal.cfg file.

5. Documentation - we do need to add documention to the python module in the 
same format as the rest of Madrigal python code.  See my modules in 
source/madpy/madrigal for examples.  I use happydoc to automatically create 
documentation from comments in code, so if you could follow that format as close 
as possible, that would be great.

That's it for changes.  I did look at using the Python special interest group 
project PIL (Python Imaging Library) as the converter instead of gs, but it 
didn't seem to handle postscript, so I think your approach is best.

Again, thanks for the excellent contribution and let me know if you want to make 
the above changes.

Bill


-- 
Bill Rideout
MIT Haystack Observatory
Email: brideout at haystack.mit.edu
Phone: 781 981-5624



More information about the OpenMadrigal-developers mailing list