From 8ce7b74671473cf81752039ba0418a7334866677 Mon Sep 17 00:00:00 2001 From: Vinayak Mehta Date: Tue, 13 Sep 2016 17:35:07 +0530 Subject: [PATCH] Replace imagemagick with ghostscript * Replace imagemagick with ghostscript * Add quiet option * Avoid repetition * Remove Wand requirement * Replace jpeg with png --- camelot/lattice.py | 17 +++++++++++------ camelot/stream.py | 2 +- requirements.txt | 1 - 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/camelot/lattice.py b/camelot/lattice.py index 2902b50..3819fbb 100644 --- a/camelot/lattice.py +++ b/camelot/lattice.py @@ -1,10 +1,9 @@ from __future__ import division import os import types -import copy_reg import logging - -from wand.image import Image +import copy_reg +import subprocess from .imgproc import (adaptive_threshold, find_lines, find_table_contours, find_table_joints) @@ -91,9 +90,15 @@ class Lattice: os.path.basename(bname))) return None - imagename = ''.join([bname, '.png']) - with Image(filename=pdfname, depth=8, resolution=300) as png: - png.save(filename=imagename) + imagename = ''.join([bname, '.jpg']) + gs_call = [ + "-q", "-sDEVICE=png16m", "-o", imagename, "-r600", pdfname + ] + if "ghostscript" in subprocess.check_output(["gs", "-version"]).lower(): + gs_call.insert(0, "gs") + else: + gs_call.insert(0, "gsc") + subprocess.call(gs_call) img, threshold = adaptive_threshold(imagename, invert=self.invert) pdf_x = width diff --git a/camelot/stream.py b/camelot/stream.py index fb06c38..010b0d7 100644 --- a/camelot/stream.py +++ b/camelot/stream.py @@ -1,8 +1,8 @@ from __future__ import division import os import types -import copy_reg import logging +import copy_reg import numpy as np diff --git a/requirements.txt b/requirements.txt index 5744ce0..6dda062 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,3 @@ pdfminer pyexcel-xlsx PyPDF2 Sphinx -Wand