/usr/share/pyshared/plasTeX/Imagers/gspdfpng.py is in python-plastex 0.9.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | from plasTeX.Logging import getLogger
import plasTeX.Imagers, glob, sys
status = getLogger('status')
gs = 'gs'
if sys.platform.startswith('win'):
gs = 'gswin32c'
class GSPDFPNG(plasTeX.Imagers.Imager):
""" Imager that uses gs to convert pdf to png """
command = ('%s -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -r250 ' % gs) + \
'-dGraphicsAlphaBits=4 -sOutputFile=img%d.png'
compiler = 'pdflatex'
fileExtension = '.png'
def executeConverter(self, output):
res = plasTeX.Imagers.Imager.executeConverter(self, output)
self.scaleImages()
return res
def scaleImages(self):
""" Scale images down and anti-alias """
if plasTeX.Imagers.PILImage is not None:
PILImage = plasTeX.Imagers.PILImage
scaledown = 2.2
for filename in glob.glob('img*.png'):
status.info('[%s]' % filename,)
img = plasTeX.Imagers.autoCrop(PILImage.open(filename),
margin=3)[0]
width, height = [int(float(x)/scaledown) for x in img.size]
img = img.resize((width, height), PILImage.ANTIALIAS)
img = img.point(self.toWhite)
img.save(filename)
def toWhite(self, pixel):
if pixel >= 245:
return 255
return pixel
def formatConfigOptions(self, config):
options = []
if config['resolution']:
options.append(('-r%s' % config['resolution'], ''))
return options
Imager = GSPDFPNG
|