From b706a1ade5e6086ba12ee960e8cbd8c3c4a10bc1 Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Mon, 21 Jul 2008 08:53:06 +0000 Subject: [PATCH] As ImageMagick output is different for different versions, and different (even incompatible) options are to be used to obtain the same result, it is better to query the version and accordingly use the needed options (bug 4749). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25758 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/scripts/convertDefault.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/scripts/convertDefault.py b/lib/scripts/convertDefault.py index 54e4f213dc..10dc4afee1 100644 --- a/lib/scripts/convertDefault.py +++ b/lib/scripts/convertDefault.py @@ -17,21 +17,26 @@ # replacement in ~/.lyx/scripts # converts an image from $1 to $2 format -import os, sys +import os, re, sys + +# We may need some extra options only supported by recent convert versions +re_version = re.compile(r'^Version:.*ImageMagick\s*(\d*)\.(\d*)\.(\d*).*$') +fout = os.popen('convert -version 2>&1') +output = fout.readline() +fout.close() +version = re_version.match(output) +major = int(version.group(1)) +minor = int(version.group(2)) +patch = int(version.group(3)) opts = "-depth 8" -# for pdf source formats, check whether convert supports the -define option -if sys.argv[1][:4] == 'pdf:': - defopt = "-define pdf:use-cropbox=true" - fout = os.popen('convert ' + defopt + ' 2>&1') - output = fout.read() - fout.close() - if not 'unrecognized' in output.lower(): - opts = defopt + ' ' + opts - -# for ppm target formats, we need to flatten image, as ppm has no support -# for alpha channel, see bug 4749 -if sys.argv[2][:4] == 'ppm:': + +# If supported, add the -define option for pdf source formats +if sys.argv[1][:4] == 'pdf:' and major >= 6 and minor >= 0 and patch >= 0: + opts = '-define pdf:use-cropbox=true ' + opts + +# If supported, add the -flatten option for ppm target formats (see bug 4749) +if sys.argv[2][:4] == 'ppm:' and major >= 6 and minor >= 0 and patch >= 0: opts = opts + ' -flatten' if os.system(r'convert %s "%s" "%s"' % (opts, sys.argv[1], sys.argv[2])) != 0: -- 2.39.2