]> git.lyx.org Git - lyx.git/blob - lib/scripts/convertDefault.py
Fix bug http://bugzilla.lyx.org/show_bug.cgi?id=4749 .
[lyx.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, sys
21
22 opts = "-depth 8"
23 # for pdf source formats, check whether convert supports the -define option
24 if sys.argv[1][:4] == 'pdf:':
25     defopt = "-define pdf:use-cropbox=true"
26     fout = os.popen('convert ' + defopt + ' 2>&1')
27     output = fout.read()
28     fout.close()
29     if not 'unrecognized' in output.lower():
30         opts = defopt + ' ' + opts
31
32 # for ppm target formats, we need to flatten image, as ppm has no support
33 # for alpha channel, see bug 4749
34 if sys.argv[2][:4] == 'ppm:':
35     opts = opts + ' -flatten'
36
37 if os.system(r'convert %s "%s" "%s"' % (opts, sys.argv[1], sys.argv[2])) != 0:
38     print >> sys.stderr, sys.argv[0], 'ERROR'
39     print >> sys.stderr, 'Execution of "convert" failed.'
40     sys.exit(1)