Exemplo n.º 1
0
def make_pdf_to_png_converter():
    """
    Returns a function that converts a pdf file to a png file.
    """

    tools_available = []
    # check for pdftocairo
    try:
        check_output(["pdftocairo", "-v"], stderr=subprocess.STDOUT)
        tools_available.append("pdftocairo")
    except:
        pass
    # check for ghostscript
    gs, ver = mpl.checkdep_ghostscript()
    if gs:
        tools_available.append("gs")

    # pick converter
    if "pdftocairo" in tools_available:
        def cairo_convert(pdffile, pngfile, dpi):
            cmd = ["pdftocairo", "-singlefile", "-png",
                   "-r %d" % dpi, pdffile, os.path.splitext(pngfile)[0]]
            # for some reason this doesn't work without shell
            check_output(" ".join(cmd), shell=True, stderr=subprocess.STDOUT)
        return cairo_convert
    elif "gs" in tools_available:
        def gs_convert(pdffile, pngfile, dpi):
            cmd = [gs, '-dQUIET', '-dSAFER', '-dBATCH', '-dNOPAUSE', '-dNOPROMPT',
                   '-sDEVICE=png16m', '-dUseCIEColor', '-dTextAlphaBits=4',
                   '-dGraphicsAlphaBits=4', '-dDOINTERPOLATE', '-sOutputFile=%s' % pngfile,
                   '-r%d' % dpi, pdffile]
            check_output(cmd, stderr=subprocess.STDOUT)
        return gs_convert
    else:
        raise RuntimeError("No suitable pdf to png renderer found.")
Exemplo n.º 2
0
def _update_converter():
    gs, gs_v = matplotlib.checkdep_ghostscript()
    if gs_v is not None:
        def cmd(old, new):
            return [str(gs), '-q', '-sDEVICE=png16m', '-dNOPAUSE', '-dBATCH',
             '-sOutputFile=' + new, old]
        converter['pdf'] = make_external_conversion_command(cmd)
        converter['eps'] = make_external_conversion_command(cmd)

    if matplotlib.checkdep_inkscape() is not None:
        converter['svg'] = _SVGConverter()
Exemplo n.º 3
0
def _update_converter():
    gs, gs_v = matplotlib.checkdep_ghostscript()
    if gs_v is not None:
        def cmd(old, new):
            return [str(gs), '-q', '-sDEVICE=png16m', '-dNOPAUSE', '-dBATCH',
             '-sOutputFile=' + new, old]
        converter['pdf'] = make_external_conversion_command(cmd)
        converter['eps'] = make_external_conversion_command(cmd)

    if matplotlib.checkdep_inkscape() is not None:
        converter['svg'] = _SVGConverter()
Exemplo n.º 4
0
def _update_converter():
    gs, gs_v = matplotlib.checkdep_ghostscript()
    if gs_v is not None:
        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)

    if matplotlib.checkdep_inkscape() is not None:
        cmd = lambda old, new: \
            ['inkscape', '-z', old, '--export-png', new]
        converter['svg'] = make_external_conversion_command(cmd)
Exemplo n.º 5
0
def _update_converter():
    gs, gs_v = matplotlib.checkdep_ghostscript()
    if gs_v is not None:
        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)

    if matplotlib.checkdep_inkscape() is not None:
        cmd = lambda old, new: \
            ['inkscape', '-z', old, '--export-png', new]
        converter['svg'] = make_external_conversion_command(cmd)
Exemplo n.º 6
0
def _update_converter():
    gs, gs_v = matplotlib.checkdep_ghostscript()
    if gs_v is not None:

        def cmd(old, new):
            return [gs, "-q", "-sDEVICE=png16m", "-dNOPAUSE", "-dBATCH", "-sOutputFile=" + new, old]

        converter["pdf"] = make_external_conversion_command(cmd)
        converter["eps"] = make_external_conversion_command(cmd)

    if matplotlib.checkdep_inkscape() is not None:

        def cmd(old, new):
            return ["inkscape", "-z", old, "--export-png", new]

        converter["svg"] = make_external_conversion_command(cmd)
Exemplo n.º 7
0
def get_file_hash(path, block_size=2 ** 20):
    md5 = hashlib.md5()
    with open(path, 'rb') as fd:
        while True:
            data = fd.read(block_size)
            if not data:
                break
            md5.update(data)

    if path.endswith('.pdf'):
        from matplotlib import checkdep_ghostscript
        md5.update(checkdep_ghostscript()[1].encode('utf-8'))
    elif path.endswith('.svg'):
        from matplotlib import checkdep_inkscape
        md5.update(checkdep_inkscape().encode('utf-8'))

    return md5.hexdigest()
Exemplo n.º 8
0
def get_file_hash(path, block_size=2 ** 20):
    md5 = hashlib.md5()
    with open(path, 'rb') as fd:
        while True:
            data = fd.read(block_size)
            if not data:
                break
            md5.update(data)

    if path.endswith('.pdf'):
        from matplotlib import checkdep_ghostscript
        md5.update(checkdep_ghostscript()[1].encode('utf-8'))
    elif path.endswith('.svg'):
        from matplotlib import checkdep_inkscape
        md5.update(checkdep_inkscape().encode('utf-8'))

    return md5.hexdigest()
Exemplo n.º 9
0
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        stdout, stderr = pipe.communicate()
        errcode = pipe.wait()
        if not os.path.exists(newname) or errcode:
            msg = "Conversion command failed:\n%s\n" % ' '.join(cmdline)
            if stdout:
                msg += "Standard output:\n%s\n" % stdout
            if stderr:
                msg += "Standard error:\n%s\n" % stderr
            raise IOError(msg)

    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)

if matplotlib.checkdep_inkscape() is not None:
    cmd = lambda old, new: \
              ['inkscape', '-z', old, '--export-png', new]
    converter['svg'] = make_external_conversion_command(cmd)
Exemplo n.º 10
0
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

import io
import re
import numpy as np
import six

import matplotlib
import matplotlib.pyplot as plt
from matplotlib import patheffects
from matplotlib.testing.decorators import cleanup, knownfailureif


needs_ghostscript = knownfailureif(
    matplotlib.checkdep_ghostscript()[0] is None,
    "This test needs a ghostscript installation")


needs_tex = knownfailureif(
    not matplotlib.checkdep_tex(),
    "This test needs a TeX installation")


def _test_savefig_to_stringio(format='ps', use_log=False):
    fig, ax = plt.subplots()
    buffers = [
        six.moves.StringIO(),
        io.StringIO(),
        io.BytesIO()]
Exemplo n.º 11
0
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

import io
import re
import numpy as np
import six

import matplotlib
import matplotlib.pyplot as plt
from matplotlib import patheffects
from matplotlib.testing.decorators import cleanup, knownfailureif

needs_ghostscript = knownfailureif(
    matplotlib.checkdep_ghostscript()[0] is None,
    "This test needs a ghostscript installation")

needs_tex = knownfailureif(not matplotlib.checkdep_tex(),
                           "This test needs a TeX installation")


def _test_savefig_to_stringio(format='ps', use_log=False):
    fig, ax = plt.subplots()
    buffers = [six.moves.StringIO(), io.StringIO(), io.BytesIO()]

    if use_log:
        ax.set_yscale('log')

    ax.plot([1, 2], [1, 2])
    ax.set_title("Déjà vu")
Exemplo n.º 12
0
   def convert(old, new):
      cmdline = cmd(old, new)
      pipe = subprocess.Popen(cmdline, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
      stdout, stderr = pipe.communicate()
      errcode = pipe.wait()
      if not os.path.exists(new) or errcode:
         msg = "Conversion command failed:\n%s\n" % ' '.join(cmdline)
         if stdout:
            msg += "Standard output:\n%s\n" % stdout
         if stderr:
            msg += "Standard error:\n%s\n" % stderr
         raise IOError(msg)

   return convert

if matplotlib.checkdep_ghostscript() is not None:
    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)

if matplotlib.checkdep_inkscape() is not None:
   cmd = lambda old, new: \
             ['inkscape', '-z', old, '--export-png', new]
   converter['svg'] = make_external_conversion_command(cmd)
Exemplo n.º 13
0
def _update_converter():
    gs, gs_v = matplotlib.checkdep_ghostscript()
    if gs_v is not None:
        converter['pdf'] = converter['eps'] = _GSConverter()
    if matplotlib.checkdep_inkscape() is not None:
        converter['svg'] = _SVGConverter()
Exemplo n.º 14
0
   def convert(old, new):
      cmdline = cmd(old, new)
      pipe = subprocess.Popen(cmdline, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
      stdout, stderr = pipe.communicate()
      errcode = pipe.wait()
      if not os.path.exists(new) or errcode:
         msg = "Conversion command failed:\n%s\n" % ' '.join(cmdline)
         if stdout:
            msg += "Standard output:\n%s\n" % stdout
         if stderr:
            msg += "Standard error:\n%s\n" % stderr
         raise IOError(msg)

   return convert

gs, gs_v = matplotlib.checkdep_ghostscript()
if gs_v is not None:
    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)

if matplotlib.checkdep_inkscape() is not None:
   cmd = lambda old, new: \
             ['inkscape', '-z', old, '--export-png', new]
   converter['svg'] = make_external_conversion_command(cmd)

def comparable_formats():
   '''Returns the list of file formats that compare_images can compare
   on this system.'''
Exemplo n.º 15
0
def _update_converter():
    gs, gs_v = matplotlib.checkdep_ghostscript()
    if gs_v is not None:
        converter['pdf'] = converter['eps'] = _GSConverter()
    if matplotlib.checkdep_inkscape() is not None:
        converter['svg'] = _SVGConverter()
Exemplo n.º 16
0
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        stdout, stderr = pipe.communicate()
        errcode = pipe.wait()
        if not os.path.exists(new) or errcode:
            msg = "Conversion command failed:\n%s\n" % ' '.join(cmdline)
            if stdout:
                msg += "Standard output:\n%s\n" % stdout
            if stderr:
                msg += "Standard error:\n%s\n" % stderr
            raise IOError(msg)

    return convert


gs, gs_v = matplotlib.checkdep_ghostscript()
if gs_v is not None:
    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)

if matplotlib.checkdep_inkscape() is not None:
    cmd = lambda old, new: \
              ['inkscape', '-z', old, '--export-png', new]
    converter['svg'] = make_external_conversion_command(cmd)


def comparable_formats():
    '''Returns the list of file formats that compare_images can compare