From 46eb4985359ca5f52b8ccbad9d7ad11ba77b67d2 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 19 Nov 2015 03:20:12 +0100 Subject: prefer graphicsmagick over imagemagick MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/plugins/image.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/plugins/image.py b/src/plugins/image.py index 20511e5..5653ed7 100644 --- a/src/plugins/image.py +++ b/src/plugins/image.py @@ -71,7 +71,8 @@ class Image: if not convert.wait() == 0: raise Exception('Image could not be converted') - convert = ['convert', '-', '-background', background, '-alpha', 'remove', '-depth', '8'] + convert = ['gm'] if Image.have_graphicsmagick() else [] + convert += ['convert', '-', '-background', background, '-alpha', 'remove', '-depth', '8'] if width is not None: convert += ['-resize', '%ix%i!' % (width, height)] convert += ['ppm:-'] @@ -130,6 +131,21 @@ class Image: bar.window.put_image(bar.gc, x, y, self.width, self.height, self.format, self.depth, 0, self.data) + @staticmethod + def have_graphicsmagick(): + ''' + Figure out whether graphicsmagick is installed + + @return :bool Whether graphicsmagick is installed + ''' + import os + path = os.environ['PATH'] if 'PATH' in os.environ else '/usr/local/bin:/usr/bin:/bin'; + for p in [p + '/gm' for p in path.split(':') if not p == '']: + if os.access(p, os.X_OK): + return True + return False + + @staticmethod def find_icon(name, width, height, preferences): ''' -- cgit v1.2.3-70-g09d2