[reportlab-users] new version of pdfimages.py

Oliver Bleutgen reportlab-users@reportlab.com
Sun, 05 Oct 2003 20:26:01 +0200


This is a multi-part message in MIME format.
--------------010607030509090602080308
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Attached is a partial rewrite of pdfimages.py and two trivial patches to 
canvas.py and rl_config.py in order to be able to use the old and the 
new version in parallel. Apply the patches and put pdfimages_ng.py into 
pdfgen/ and set rl_config.use_pdfimages_ng=1 for using it.

What's changed:
- when an filename is passed to __init__, PIL is used to determine 
filetype etc. and calls _handle_xxx() methods to deal with the file.
If there's no such method, it calls _generic_handler() which uses PIL
to get and process the image data. _handle_jpeg() is the only 
specialized method for now.
- _generic_handler() is also used if PIL.Image instances are passed
- both methods don't convert the image if it's grayscale, RGB or CMYK,
but do pass the right PDF object dictionary.
- _handle_jpeg() recogizes the broken adobe CMYK jpegs, and puts an 
extra argument into their pdf header to invert them when displayed

I tested this with jpeg and tif files with grayscale, RGB and CMYK 
graphics, and also with the stock reportlab tests.

cheers,
oliver


--------------010607030509090602080308
Content-Type: application/x-zip-compressed;
 name="pdfimages_ng.zip"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 filename="pdfimages_ng.zip"

UEsDBBQAAAAIAI2gRS/x1BhIPAsAAOEhAAAPAAAAcGRmaW1hZ2VzX25nLnB5zVltj9s2Ev6+
wP6HgTeF7FSRvWlTLIxzg2R3k7pN01wToDnsGYIs0bYSWdRR9HqdQ//7zQwpiZK9TnL90hRd
S+KQHM4888qzWBY7lS5XGn4XhVT6VTSHaR4H8Hg0Gp2enJVCQJbGIi9FoO80LKSq3iEROkqz
EqlWaaml2sFK62I8HMa3ZVDKjYoFki9FkAs9jJfpo3ma09hWzAN8HSreMYvmwyJZLEVOP+k6
WooyKHZPkVBJqSc1Fe7z4CcRJUKN4efx0I4fWSXMl7iQfwvnwfd0nu+G56Ph6AmcX4xH348f
/wBrAdd3BTw4PQnDW6HKVOZhOPE8Dx5MkzF8/UKA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