py2app icon indicating copy to clipboard operation
py2app copied to clipboard

Pillow and PdfImagePlugin

Open hasii2011 opened this issue 11 months ago • 1 comments

Running

py2app 0.28.8
python 3.12.7

Trying to use the above to convert an image to PDF. I get this error:

raceback (most recent call last):
  File "pyut/ui/main/PyutUI.pyc", line 733, in _onFrameInformation
  File "pyutplugins/plugininterfaces/IOPluginInterface.pyc", line 85, in _executeExport
  File "pyutplugins/ioplugins/IOPdf.pyc", line 144, in write
  File "pyimage2pdf/PyImage2Pdf.pyc", line 101, in convert
  File "pyimage2pdf/PyImage2Pdf.pyc", line 137, in _createInitialPdf
  File "PIL/Image.pyc", line 2591, in save
KeyError: 'PDF'

A closer look at what Image was trying to index into was its dictionary of plugins. When this fails the dictionary looks like this:

{'BMP': <function _save at 0x10e09ade0>, 'DIB': <function _dib_save at 0x10e09a980>,
 'GIF': <function _save at 0x10e12c180>, 'JPEG': <function _save at 0x10e12d620>, 
 'PPM': <function _save at 0x10e12da80>, 'PNG': <function _save at 0x10e121300>, 
 'TIFF': <function _save at 0x10e16dc60>, 'MPO': <function _save at 0x10e175da0>}

When I run the code from my IDE (PyCharm) it looks like this

{'BMP': <function _save at 0x10fcba020>, 'DIB': <function _dib_save at 0x10fcb9bc0>,
 'GIF': <function _save at 0x10fcb39c0>, 'JPEG': <function _save at 0x10fcc9080>,
 'PPM': <function _save at 0x10fcc9620>, 'PNG': <function _save at 0x10fcd4f40>,
 'BLP': <function _save at 0x10fcd5b20>, 'BUFR': <function _save at 0x10fcd67a0>,
 'PCX': <function _save at 0x10fcd7240>, 'DDS': <function _save at 0x10fcd77e0>,
 'EPS': <function _save at 0x10fcd7f60>, 'GRIB': <function _save at 0x10fcf58a0>,
 'HDF5': <function _save at 0x10fcf5da0>, 'JPEG2000': <function _save at 0x10fcf7a60>,
 'ICNS': <function _save at 0x10fcf7ce0>, 'ICO': <function _save at 0x10fd08720>,
 'IM': <function _save at 0x10fd09580>, 'TIFF': <function _save at 0x11a2ef9c0>,
 'MPO': <function _save at 0x10fd0ae80>, 'MSP': <function _save at 0x11a2f8040>,
 'PALM': <function _save at 0x11a2f8540>, 'PDF': <function _save at 0x11a2fa7a0>,
 'SGI': <function _save at 0x11a314e00>, 'SPIDER': <function _save_spider at 0x11a315bc0>,
 'TGA': <function _save at 0x11a316020>, 'WEBP': <function _save at 0x11a316ca0>,
 'WMF': <function _save at 0x11a317060>, 'XBM': <function _save at 0x11a317560>}

A much bigger plugin list.

I wrote a small demo program that illustrates this issue: It is here:

hasii2011 avatar Jan 19 '25 22:01 hasii2011

Found a work around. If I manually import the plugin then the demo program works. I updated the code example and left the work around commented out

# from PIL import PdfImagePlugin

hasii2011 avatar Jan 21 '25 19:01 hasii2011