Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for .MPO images #787

Open
adkl opened this issue Jan 19, 2022 · 2 comments
Open

Support for .MPO images #787

adkl opened this issue Jan 19, 2022 · 2 comments

Comments

@adkl
Copy link

adkl commented Jan 19, 2022

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)

@MartinPacker
Copy link

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.)

@adkl
Copy link
Author

adkl commented Jan 20, 2022

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: python-pillow/Pillow#1138 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants