tufte layout files:
[lyx.git] / lib / scripts / convertDefault.py
blob6cd01632af9ec69e338a421dc5439f759e874e68
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 # file convertDefault.py
5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
8 # \author Herbert Voß
9 # \author Bo Peng
11 # Full author contact details are available in file CREDITS.
13 # The default converter if no other has been defined by the user from the
14 # Conversion->Converter tab of the Preferences dialog.
16 # The user can also redefine this default converter, placing their
17 # replacement in ~/.lyx/scripts
19 # converts an image from $1 to $2 format
20 import os, re, sys
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)
29 # Imagemagick by default
30 gm = 0
32 if version != None:
33 major = int(version.group(1))
34 minor = int(version.group(2))
35 patch = int(version.group(3))
36 version = hex(major * 65536 + minor * 256 + patch)
37 else:
38 # Try GraphicsMagick
39 re_version = re.compile(r'^GraphicsMagick.*http:..www.GraphicsMagick.org.*$')
40 version = re_version.match(output)
41 if version != None:
42 gm = 1
44 opts = "-depth 8"
46 # If supported, add the -define option for pdf source formats
47 if sys.argv[1][:4] == 'pdf:' and (version >= 0x060206 or gm):
48 opts = '-define pdf:use-cropbox=true ' + opts
50 # If supported, add the -flatten option for ppm target formats (see bug 4749)
51 if sys.argv[2][:4] == 'ppm:' and (version >= 0x060305 or gm):
52 opts = opts + ' -flatten'
54 if os.system(r'convert %s "%s" "%s"' % (opts, sys.argv[1], sys.argv[2])) != 0:
55 print >> sys.stderr, sys.argv[0], 'ERROR'
56 print >> sys.stderr, 'Execution of "convert" failed.'
57 sys.exit(1)