]> git.lyx.org Git - features.git/blob - lib/scripts/convertDefault.py
Tailor version numbers according to IM ChangeLogs:
[features.git] / lib / scripts / convertDefault.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 # file convertDefault.py
5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
7
8 # \author Herbert Voß
9 # \author Bo Peng
10
11 # Full author contact details are available in file CREDITS.
12
13 # The default converter if no other has been defined by the user from the
14 # Conversion->Converter tab of the Preferences dialog.
15
16 # The user can also redefine this default converter, placing their
17 # replacement in ~/.lyx/scripts
18
19 # converts an image from $1 to $2 format
20 import os, re, sys
21
22 # We may need some extra options only supported by recent convert versions
23 re_version = re.compile(r'^Version:.*ImageMagick\s*(\d*)\.(\d*)\.(\d*).*$')
24 fout = os.popen('convert -version 2>&1')
25 output = fout.readline()
26 fout.close()
27 version = re_version.match(output)
28 major = int(version.group(1))
29 minor = int(version.group(2))
30 patch = int(version.group(3))
31
32 opts = "-depth 8"
33
34 # If supported, add the -define option for pdf source formats 
35 if sys.argv[1][:4] == 'pdf:' and major >= 6 and minor >= 2 and patch >= 6:
36     opts = '-define pdf:use-cropbox=true ' + opts
37
38 # If supported, add the -flatten option for ppm target formats (see bug 4749)
39 if sys.argv[2][:4] == 'ppm:' and major >= 6 and minor >= 0 and patch >= 0:
40     opts = opts + ' -flatten'
41
42 if os.system(r'convert %s "%s" "%s"' % (opts, sys.argv[1], sys.argv[2])) != 0:
43     print >> sys.stderr, sys.argv[0], 'ERROR'
44     print >> sys.stderr, 'Execution of "convert" failed.'
45     sys.exit(1)