Turn images to grayscale by default
This commit is contained in:
parent
d196ed2978
commit
7d53f05f39
|
@ -51,6 +51,12 @@ from pythonlib.ziputils import unzipToDirectory
|
|||
from pythonlib.utf8utils import utf8encode
|
||||
from pythonlib import magic
|
||||
|
||||
try:
|
||||
import PIL
|
||||
import PIL.Image
|
||||
except ImportError:
|
||||
PIL = None
|
||||
|
||||
tempfilelock = threading.Lock()
|
||||
tempfile.template = "F%ld-" % time.time()
|
||||
|
||||
|
@ -289,7 +295,9 @@ def convertTex2Pdf(d, latexFileName):
|
|||
subprocess.call([cmd], cwd=d, shell=True)
|
||||
subprocess.call([cmd], cwd=d, shell=True )
|
||||
|
||||
def convertLegi2Pdf(inputFileName, pdfFileName, latexFileName, keepLatex=0, debug=0, annexes=[], draft=0, toc=True, style="normal", useFont=None, legacyMode=True):
|
||||
def convertLegi2Pdf(inputFileName, pdfFileName, latexFileName, keepLatex=0,
|
||||
debug=0, annexes=[], draft=0, toc=True, style="normal", useFont=None,
|
||||
legacyMode=True, grayscale=True):
|
||||
"""
|
||||
Based on input .legi document, generatePdf is responsible
|
||||
to generate a PDF documents.
|
||||
|
@ -315,6 +323,14 @@ def convertLegi2Pdf(inputFileName, pdfFileName, latexFileName, keepLatex=0, debu
|
|||
contentEntryInfo, contentEntryData = allEntries.get( nameContentLegi, (None, None))
|
||||
if contentEntryInfo == None or contentEntryData == None:
|
||||
raise PdfGeneratorException, 'Corrupted legi file: No %s entry' % (nameContentLegi)
|
||||
if grayscale and PIL:
|
||||
for filename in os.listdir(tempDir):
|
||||
if not os.path.splitext(filename)[-1] in ('.jpg', '.png'):
|
||||
continue
|
||||
# image, convert it to grayscale
|
||||
image = PIL.Image.open(os.path.join(tempDir, filename))
|
||||
grayscaled = image.convert('L')
|
||||
grayscaled.save(os.path.join(tempDir, filename))
|
||||
elif fmt == "xml":
|
||||
contentEntryData = f.read()
|
||||
_writeToFile(os.path.join(tempDir, nameContentLegi), contentEntryData)
|
||||
|
|
|
@ -43,6 +43,7 @@ Usage: pdfGenerator.py [options]
|
|||
--parchemin or -p: style parchemin
|
||||
--bqr or -q: style BQR
|
||||
--legacy: legacy mode (old XSL and TeX)
|
||||
--nograyscale: do not convert to grayscale
|
||||
|
||||
annexe definition = "filename|title|scale"
|
||||
|
||||
|
@ -69,12 +70,14 @@ if __name__ == '__main__':
|
|||
style= "normal"
|
||||
annexes = []
|
||||
legacyMode = False
|
||||
grayscale = True
|
||||
|
||||
optlist, args = getopt.getopt(sys.argv[1:],
|
||||
'i:o:t:a:hldbpq',
|
||||
['input-file=', 'output-pdf-file=', 'output-latex-file=',
|
||||
'annexe=', 'help', 'latex', 'debug', 'brouillon', 'notoc',
|
||||
'parchemin', 'bqr', 'use-font=', 'legacy', 'ng'])
|
||||
'parchemin', 'bqr', 'use-font=', 'legacy', 'ng',
|
||||
'nograyscale'])
|
||||
|
||||
for option,value in optlist:
|
||||
if option == '-i' or option == '--input-file':
|
||||
|
@ -103,6 +106,8 @@ if __name__ == '__main__':
|
|||
style = "bqr"
|
||||
elif option == '--notoc':
|
||||
toc = False
|
||||
elif option == '--nograyscale':
|
||||
grayscale = False
|
||||
elif option == '-a' or option == '--annexe':
|
||||
r = value.split('|')
|
||||
if len(r) == 1:
|
||||
|
@ -133,7 +138,8 @@ if __name__ == '__main__':
|
|||
outputLatexFile = outputPdfFile + '.tex'
|
||||
|
||||
convertLegi2Pdf(inputFile, outputPdfFile, outputLatexFile, keepLatex,
|
||||
debug, annexes, draft, toc, style, useFont, legacyMode)
|
||||
debug, annexes, draft, toc, style, useFont, legacyMode,
|
||||
grayscale)
|
||||
if help:
|
||||
printUsage()
|
||||
else:
|
||||
|
|
Reference in New Issue