deprecations in Pillow >= 8.0 brakes renderPM.drawToFile

470 views
Skip to first unread message

Marius Stanciu

unread,
Oct 24, 2020, 7:31:31 PM10/24/20
to reportlab-users
Hello,
Reportlab 3.5.53 with Pillow 8.0.1

I got an error when using:
renderPM.drawToFile(drawing, filename, 'PNG')

The error I get is:
"'Image' object has no attribute 'fromstring'"

Seeing this I tried different versions of the Pillow package and saw that Pillow 7.2 still works.

The error comes due of the fact that the fromstring attribute in Pillow Image is deprecated from 2013 and it was removed in Commit #4798 on the Pillow Git:

Modifying this method from renderPM.py file by removing the optional default parameter:

def  toPIL(self):
        im = _getImage().new('RGB', size=(self._gs.width, self._gs.height))
        getattr(im,'frombytes',getattr(im,'fromstring'))(self._gs.pixBuf)
        return im

to:

def  toPIL(self):
        im = _getImage().new('RGB', size=(self._gs.width, self._gs.height))
        getattr(im,'frombytes')(self._gs.pixBuf)
        return im

seems to solve the issue.

I hope this report will help.

Best regards,
Marius

Marius Stanciu

unread,
Oct 28, 2020, 6:35:07 PM10/28/20
to reportlab-users

Hi,

Thanks for the fix provided so fast!
Reportlab 3.5.54 solved the issue.

All the best,
Marius 
Reply all
Reply to author
Forward
0 new messages