Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit d638c9b5eed082e509cb6f39019be5a92af9ac1f 1 parent b3c7bcd
Michael Droettboom authored April 17, 2012
7  doc/devel/coding_guide.rst
Source Rendered
@@ -381,6 +381,13 @@ The following software is required to run the tests:
381 381
 
382 382
   - `Inkscape <http://inkscape.org>`_ (to render SVG files)
383 383
 
  384
+For additional speed, you may also wish to install:
  385
+
  386
+  - `python-ghostscript <http://pypi.python.org/pypi/ghostscript>` (to
  387
+    use ghostscript as a library from Python)::
  388
+
  389
+      pip install ghostscript
  390
+
384 391
 Running the tests
385 392
 -----------------
386 393
 
37  lib/matplotlib/testing/compare.py
@@ -138,17 +138,32 @@ def convert(old, new):
138 138
 
139 139
    return convert
140 140
 
141  
-if matplotlib.checkdep_ghostscript() is not None:
142  
-   # FIXME: make checkdep_ghostscript return the command
143  
-   if sys.platform == 'win32':
144  
-      gs = 'gswin32c'
145  
-   else:
146  
-      gs = 'gs'
147  
-   cmd = lambda old, new: \
148  
-       [gs, '-q', '-sDEVICE=png16m', '-dNOPAUSE', '-dBATCH',
149  
-        '-sOutputFile=' + new, old]
150  
-   converter['pdf'] = make_external_conversion_command(cmd)
151  
-   converter['eps'] = make_external_conversion_command(cmd)
  141
+try:
  142
+   import ghostscript
  143
+except ImportError:
  144
+   if matplotlib.checkdep_ghostscript() is not None:
  145
+      # FIXME: make checkdep_ghostscript return the command
  146
+      if sys.platform == 'win32':
  147
+         gs = 'gswin32c'
  148
+      else:
  149
+         gs = 'gs'
  150
+      cmd = lambda old, new: \
  151
+        [gs, '-q', '-sDEVICE=png16m', '-dNOPAUSE', '-dBATCH', '-dSAFER',
  152
+         '-sOutputFile=' + new, old]
  153
+      converter['pdf'] = make_external_conversion_command(cmd)
  154
+      converter['eps'] = make_external_conversion_command(cmd)
  155
+else:
  156
+   def ghostscript_lib_converter(old, new):
  157
+      args = [
  158
+          'matplotlib', '-q', '-sDEVICE=png16m', '-dNOPAUSE', '-dBATCH',
  159
+          '-dSAFER', '-sOutputFile=' + new, old]
  160
+      try:
  161
+         gs = ghostscript.Ghostscript(*args)
  162
+      finally:
  163
+         gs.exit()
  164
+         ghostscript.cleanup()
  165
+   converter['pdf'] = ghostscript_lib_converter
  166
+   converter['eps'] = ghostscript_lib_converter
152 167
 
153 168
 if matplotlib.checkdep_inkscape() is not None:
154 169
    cmd = lambda old, new: \

0 notes on commit d638c9b

Please sign in to comment.
Something went wrong with that request. Please try again.