Open adkl opened 2 years ago
I think you're asking python-pptx to convert MPO to, say, PNG. I wouldn't ask python-pptx to do that. I'd find another converter and do it in batch.
(In my code I convert EPS or SVG to PNG before embedding with python-pptx.)
That's a good point, but JPEG images encoded as MPO images are basically working nice when inserted through any program working with presentations. Also, MPO images are often saved with .jpeg
extension, and in order to make this work, we put the responsibility to each client working with the lib to convert "fake jpeg" pictures to real jpeg. This means each client needs to look at the image type not based on the extension but on the content. This should be the responsibility of the library.
I looked into the code and it fails only because pillow
recognizes a JPEG image as an MPO image, but essentially it is a JPEG image consisting of many layers. Of course, I am not asking python-pptx
to convert from one to another (because it doesn't have to), but just not to fail if someone inserts a picture that is essentially JPEG, but captured with a smartphone portrait mode (this is the concrete example from iPhone).
It can be fixed using monkey patching easily, but probably not recommended. I assume there is a clever way - to add a custom pillow
plugin for such files.
This is just an improvement to keep in track with the latest technologies, saving JPEG pictures in form of MPOs when taking with Portrait modes on smartphones (because of the depth sensor), people will work with such images in the long run.
For reference: https://github.com/python-pillow/Pillow/issues/1138#issuecomment-84088753
Currently, .MPO images are not supported.
I took a photo with an iPhone in portrait mode, which encodes images in .MPO format: https://fileinfo.com/extension/mpo
Although the picture was saved in .jpeg extension, it is .MPO encoded and cannot be parsed by pptx. As this is a pretty popular technology in smartphones, probably it makes sense to support this.
Here is the error I got:
(ValueError("unsupported image format, expected one of: dict_keys(['BMP', 'GIF', 'JPEG', 'PNG', 'TIFF', 'WMF']), got 'MPO'"), False)