Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ENH: Add support to save images in WebP format#21274

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
QuLogic merged 4 commits intomatplotlib:masterfromkinshukdua:master
Oct 15, 2021
Merged

ENH: Add support to save images in WebP format#21274

QuLogic merged 4 commits intomatplotlib:masterfromkinshukdua:master
Oct 15, 2021

Conversation

kinshukdua
Copy link
Contributor

PR Summary

Fixes#21162
This adds support to save images in WebP format.
This works fine without any problem since Pillow supports WebP and the code is analogous to the support for tiff images added in PR#15193.

PR Checklist

  • Has pytest style unit tests (andpytest passes).
  • IsFlake 8 compliant (runflake8 on changed files to check).
  • [N/A] New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).
  • Conforms to Matplotlib style conventions (installflake8-docstrings and runflake8 --docstring-convention=all).
  • [N/A] New features have an entry indoc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented indoc/api/next_api_changes/ (follow instructions in README.rst there).

ogrisel reacted with thumbs up emoji
Copy link

@github-actionsgithub-actionsbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping@matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join uson gitter for real-time discussion.

For details on testing, writing docs, and our review process, please seethe developer guide

We strive to be a welcoming and open project. Please follow ourCode of Conduct.

@tacaswelltacaswell added this to thev3.6.0 milestoneOct 4, 2021
@tacaswell
Copy link
Member

It is nice how simple this patch is to pick up a new format!

Could you add a test that saves an image to ByteIO buffer? That will be enough to exercise the code that you added. Given that this is using the Agg backend we definitely do not need to run it against the full test suite as we would then just be testing pillow. It looks likeprint_tiff is covered, maybe find that test and adapt / parameterize it?

@kinshukdua
Copy link
ContributorAuthor

@tacaswell Yes, I will add a test using ByteIO buffer.

@@ -594,6 +594,29 @@ def print_tif(self, filename_or_obj, *, pil_kwargs=None):

print_tiff = print_tif

@_check_savefig_extra_args
def print_webp(self, filename_or_obj, *, pil_kwargs=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Areall these pillow save formats the same? If so, I wonder if we just want a genericprint_pillow(format=pillow_format) rather than adding these one-by-one?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

As far as I can tell, it is the same for all the fully supported formats- BMP, DDS, DIB, EPS, GIF, ICNS, ICO, IM, JPEG, JPEG 2000, MSP, PCX, PNG, PPM, SGI, SPIDER, TGA, TIFF, WebP, XBM.
I think adding a genericprint_pillow does make a lot of sense especially if we want to support all of these formats. The tests however will have to be created for each format, as they all have their specific options that need to be tested.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thats the approach I would take, but maybe its more complex than that...

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Maybe we should leave it for a different PR then?

tacaswell reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I guess that depends on whether we thinkwebp is used enough to merit a standalone method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I suspect the way we would have to do this in general would be some mild-meta-programming as

print_method=getattr(canvas,'print_%s'%format)
is how we look up the method to use and above it we get the format via
ifformatisNone:
# get format from filename, or from backend's default filetype
ifisinstance(filename,os.PathLike):
filename=os.fspath(filename)
ifisinstance(filename,str):
format=os.path.splitext(filename)[1][1:]
ifformatisNoneorformat=='':
format=self.get_default_filetype()
ifisinstance(filename,str):
filename=filename.rstrip('.')+'.'+format
format=format.lower()
so we have to have aprint_foo method for every format.

However, we can write ourselves a print function factory function and inbackend_agg.py do something like:

for fmt in LIST_OF_PILLOW_FORMATS:   setattr(BackendAgg, f'print_{fmt}', pillow_printer_factor(fmt)

@tacaswell
Copy link
Member

@kinshukdua Would you be willing to rebase this PR? We prefer to not merge the default branch back into feature branches.

@kinshukdua
Copy link
ContributorAuthor

@tacaswell I've rebased the PR, I'm new to git so please let me know if I need to do something else.

Copy link
Member

@jklymakjklymak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think we need to decide whether we want a new webp method, a general "pass to pillow" method or a factory. If in the end, we don't want a new webp method, I dont think we can add this.

I'm not against a webp method if it really is something many folks want, but it seems obscure to me, and maybe just a general method to pillow takes care of the obscure use cases.

I'm blocking until we can sort this out, but if another core dev wants to support a standalone webp method, feel free to dismiss my review.

@jklymak
Copy link
Member

@tacaswell said that this is what we want, which is fine with me. Thanks for your patience!

Copy link
Contributor

@anntzeranntzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Please consider clarifying the situation wrt. dpi. Anyone can dismiss this.

@anntzer
Copy link
Contributor

Thanks, anyone can merge after CI passes. Congrats on getting your first PR in :)

kinshukdua reacted with heart emoji

@QuLogicQuLogic merged commit60466fb intomatplotlib:masterOct 15, 2021
@QuLogic
Copy link
Member

Thanks@kinshukdua! Congratulations on your first PR to Matplotlib 🎉 We hope to hear from you again.

kinshukdua reacted with hooray emoji

@kinshukdua
Copy link
ContributorAuthor

Thanks! It was really great contributing back to such an important open source project, I hope to continue contributing.

tacaswell, ogrisel, and itsgifnotjiff reacted with hooray emoji

tacaswell pushed a commit that referenced this pull requestOct 20, 2021
ENH: Add support to save images in WebP format
@QuLogicQuLogic mentioned this pull requestSep 9, 2022
2 tasks
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tacaswelltacaswelltacaswell left review comments

@jklymakjklymakjklymak approved these changes

@github-actionsgithub-actions[bot]github-actions[bot] left review comments

@anntzeranntzeranntzer approved these changes

@timhoffmtimhoffmtimhoffm approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
v3.6.0
Development

Successfully merging this pull request may close these issues.

[ENH]: saving images in webp format
6 participants
@kinshukdua@tacaswell@jklymak@anntzer@QuLogic@timhoffm

[8]ページ先頭

©2009-2025 Movatter.jp