renderPM.py: added preConvert/preSaveCB args and also invert option
authorrgbecker
Fri, 08 Jun 2007 14:08:37 +0000
changeset 2818 ccff6734b82b
parent 2816 5554d8b5a2c2
child 2819 0af8d3e7dfc9
renderPM.py: added preConvert/preSaveCB args and also invert option
reportlab/graphics/renderPM.py
--- a/reportlab/graphics/renderPM.py	Wed Jun 06 16:44:51 2007 +0000
+++ b/reportlab/graphics/renderPM.py	Fri Jun 08 14:08:37 2007 +0000
@@ -277,8 +277,12 @@
             fmt = os.path.splitext(fn)[1]
             if fmt.startswith('.'): fmt = fmt[1:]
         configPIL = self.configPIL or {}
+        configPIL.setdefault('preConvertCB',None)
+        preConvertCB=configPIL.pop('preConvertCB')
+        if preConvertCB:
+            im = preConvertCB(im)
         fmt = string.upper(fmt)
-        if fmt in ('GIF'):
+        if fmt in ('GIF',):
             im = _convert2pilp(im)
         elif fmt in ('TIFF','TIFFP','TIFFL','TIF','TIFF1'):
             if fmt.endswith('P'):
@@ -319,6 +323,14 @@
                 #if type(fn) is type(''): im.save(fn+'_masked.gif','GIF')
             for a,d in ('resolution',self._dpi),('resolution unit','inch'):
                 configPIL[a] = configPIL.get(a,d)
+        configPIL.setdefault('chops_invert',0)
+        if configPIL.pop('chops_invert'):
+            from PIL import ImageChops
+            im = ImageChops.invert(im)
+        configPIL.setdefault('preSaveCB',None)
+        preSaveCB=configPIL.pop('preSaveCB')
+        if preSaveCB:
+            im = preSaveCB(im)
         im.save(fn,fmt,**configPIL)
         if not hasattr(fn,'write') and os.name=='mac':
             from reportlab.lib.utils import markfilename