Permalink
Browse files

Use python-ghostscript to convert PDF and EPS to PNG (if available).

  • Loading branch information...
1 parent b3c7bcd commit d638c9b5eed082e509cb6f39019be5a92af9ac1f @mdboom committed Apr 17, 2012
Showing with 33 additions and 11 deletions.
  1. +7 −0 doc/devel/coding_guide.rst
  2. +26 −11 lib/matplotlib/testing/compare.py
@@ -381,6 +381,13 @@ The following software is required to run the tests:
- `Inkscape <http://inkscape.org>`_ (to render SVG files)
+For additional speed, you may also wish to install:
+
+ - `python-ghostscript <http://pypi.python.org/pypi/ghostscript>` (to
+ use ghostscript as a library from Python)::
+
+ pip install ghostscript
+
Running the tests
-----------------
@@ -138,17 +138,32 @@ def convert(old, new):
return convert
-if matplotlib.checkdep_ghostscript() is not None:
- # FIXME: make checkdep_ghostscript return the command
- if sys.platform == 'win32':
- gs = 'gswin32c'
- else:
- gs = 'gs'
- cmd = lambda old, new: \
- [gs, '-q', '-sDEVICE=png16m', '-dNOPAUSE', '-dBATCH',
- '-sOutputFile=' + new, old]
- converter['pdf'] = make_external_conversion_command(cmd)
- converter['eps'] = make_external_conversion_command(cmd)
+try:
+ import ghostscript
+except ImportError:
+ if matplotlib.checkdep_ghostscript() is not None:
+ # FIXME: make checkdep_ghostscript return the command
+ if sys.platform == 'win32':
+ gs = 'gswin32c'
+ else:
+ gs = 'gs'
+ cmd = lambda old, new: \
+ [gs, '-q', '-sDEVICE=png16m', '-dNOPAUSE', '-dBATCH', '-dSAFER',
+ '-sOutputFile=' + new, old]
+ converter['pdf'] = make_external_conversion_command(cmd)
+ converter['eps'] = make_external_conversion_command(cmd)
+else:
+ def ghostscript_lib_converter(old, new):
+ args = [
+ 'matplotlib', '-q', '-sDEVICE=png16m', '-dNOPAUSE', '-dBATCH',
+ '-dSAFER', '-sOutputFile=' + new, old]
+ try:
+ gs = ghostscript.Ghostscript(*args)
+ finally:
+ gs.exit()
+ ghostscript.cleanup()
+ converter['pdf'] = ghostscript_lib_converter
+ converter['eps'] = ghostscript_lib_converter
if matplotlib.checkdep_inkscape() is not None:
cmd = lambda old, new: \

0 comments on commit d638c9b

Please sign in to comment.