2006-07-17 19:41:32 +00:00
|
|
|
#!/usr/bin/env python
|
2006-08-08 10:42:59 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2003-08-22 10:50:02 +00:00
|
|
|
|
2006-06-26 14:17:12 +00:00
|
|
|
# file convertDefault.py
|
2003-08-22 10:50:02 +00:00
|
|
|
# This file is part of LyX, the document processor.
|
|
|
|
# Licence details can be found in the file COPYING.
|
|
|
|
|
2006-08-08 10:42:59 +00:00
|
|
|
# \author Herbert Voß
|
2006-06-26 14:17:12 +00:00
|
|
|
# \author Bo Peng
|
2003-08-22 10:50:02 +00:00
|
|
|
|
|
|
|
# Full author contact details are available in file CREDITS.
|
|
|
|
|
2003-01-13 23:35:18 +00:00
|
|
|
# The default converter if no other has been defined by the user from the
|
|
|
|
# Conversion->Converter tab of the Preferences dialog.
|
2003-08-22 10:50:02 +00:00
|
|
|
|
2003-01-13 23:35:18 +00:00
|
|
|
# The user can also redefine this default converter, placing their
|
|
|
|
# replacement in ~/.lyx/scripts
|
2003-08-22 10:50:02 +00:00
|
|
|
|
2003-01-13 23:35:18 +00:00
|
|
|
# converts an image from $1 to $2 format
|
2008-07-21 08:53:06 +00:00
|
|
|
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)
|
2008-07-21 10:31:26 +00:00
|
|
|
major = int(version.group(1))
|
|
|
|
minor = int(version.group(2))
|
|
|
|
patch = int(version.group(3))
|
|
|
|
version = hex(major * 65536 + minor * 256 + patch)
|
2007-03-31 18:21:54 +00:00
|
|
|
|
|
|
|
opts = "-depth 8"
|
2008-07-21 08:53:06 +00:00
|
|
|
|
|
|
|
# If supported, add the -define option for pdf source formats
|
2008-07-21 10:31:26 +00:00
|
|
|
if sys.argv[1][:4] == 'pdf:' and version >= 0x060206:
|
2008-07-21 08:53:06 +00:00
|
|
|
opts = '-define pdf:use-cropbox=true ' + opts
|
|
|
|
|
|
|
|
# If supported, add the -flatten option for ppm target formats (see bug 4749)
|
2008-07-21 10:54:12 +00:00
|
|
|
if sys.argv[2][:4] == 'ppm:' and version >= 0x060305:
|
2008-07-07 15:09:44 +00:00
|
|
|
opts = opts + ' -flatten'
|
|
|
|
|
2007-03-31 18:21:54 +00:00
|
|
|
if os.system(r'convert %s "%s" "%s"' % (opts, sys.argv[1], sys.argv[2])) != 0:
|
2006-06-27 21:08:54 +00:00
|
|
|
print >> sys.stderr, sys.argv[0], 'ERROR'
|
|
|
|
print >> sys.stderr, 'Execution of "convert" failed.'
|
|
|
|
sys.exit(1)
|