Since opening an image file with openpyxl.drawing.image.Image(), with path argument
Image(path) fails with IOError: cannot identify image file, I am now trying to open the image using PIL, then create openpyxl image from the PIL Image, like so:
pil_img = PILImage.open(path_to_image)) img = Image(pil_img)
This is the approach suggested by https://www.odoo.com/fr_FR/forum/aide-1/question/add-signature-image-stored-in-database-to-excel-file-91361
However, this fails too, because in
_import_image(img) does not recognize my image as a PILImage.
There is a test that goes like this:
if not isinstance(img, PILImage.Image): img = PILImage.open(img) return img
So that if image was recognized as PILImage.Image, it would simply be returned. But the isinstance test fails because the type is JpegImageFile (or PngImageFile).
If I comment-out the isinstance test and let it return img, it works.
Maybe the test for a PILImage instance or compatible should be refined ?
(added) Actually, passing a PIL Image created with PILImage.new(...) still fails the isinstance test. Maybe the test could be reversed: if it's a string then it's probably a file path, otherwise consider it's some kind of PILImage ?