Skip to content

ENH: Add support for WebP#1111

Merged
larsoner merged 1 commit intosphinx-gallery:masterfrom
StefRe:enh/webp
Mar 31, 2023
Merged

ENH: Add support for WebP#1111
larsoner merged 1 commit intosphinx-gallery:masterfrom
StefRe:enh/webp

Conversation

@StefRe
Copy link
Copy Markdown
Contributor

@StefRe StefRe commented Mar 21, 2023

and update docs on supported formats.

WebP yields much smaller file sizes than optimized png in only very little more time. For the Matplotlib docs with 2637 sphx-glr... files I got the following results:

Total size in MB Percentage of orginal size Extra time
plain png 162.4 100 % -
optipng -o7 115.9 71 % 4:35 hrs
webp lossless quality=100 65.5 40 % 9 mins


My first thought was to integrate the _KNOWN_IMG_EXTS list into the docstring of matplotlib_scraper but the only solution I found for it is https://stackoverflow.com/a/10308363/3944322 and I think it's a bit of overkill, isn't it?

Do we need tests for it? test_custom_scraper_thumbnail_alpha could be parameterized with _KNOWN_IMG_EXTS but I'm not sure if this really gives more/better test coverage.

Closes #1055

@StefRe StefRe marked this pull request as ready for review March 21, 2023 11:24
@larsoner
Copy link
Copy Markdown
Contributor

Do we need tests for it? test_custom_scraper_thumbnail_alpha could be parameterized with _KNOWN_IMG_EXTS but I'm not sure if this really gives more/better test coverage.

I'm less concerned about line coverage as I am about making sure the feature actually works as desired. For example, you could modify some tinybuild example to make matplotlib savefig in webp format (or whatever you're going to do in the matplotlib doc build to get it to actually use webp) then assert that sphx_glr_<something>.webp shows up on disk and in the HTML in test_full.py somewhere.

@StefRe StefRe marked this pull request as draft March 21, 2023 16:24
@StefRe
Copy link
Copy Markdown
Contributor Author

StefRe commented Mar 21, 2023

@larsoner I'm a bit at a loss: tests run locally (Win10 / Python 3.10) without errors (218 passed out of 218 collected, nothing skipped). Do you happen to have any idea how to tackle this? Installed Pillow version is 9.4.0 on CI - the same as on my local machine.

@larsoner
Copy link
Copy Markdown
Contributor

You incremented the file counter but I don't see a new example, did you forget a git add sphinx_gallery/tests/tinybuild/examples/plot_webp_thumb.py or so?

@StefRe
Copy link
Copy Markdown
Contributor Author

StefRe commented Mar 21, 2023

OMG, yes of course - there should be a sphinx_gallery/tests/tinybuild/examples/plot_webp.py that's not included here. Thank you so much! I stared for maybe an hour at the test logs but didn't see the most obvious thing.

@StefRe StefRe force-pushed the enh/webp branch 2 times, most recently from 42c1423 to 46e2501 Compare March 21, 2023 20:03
@StefRe StefRe marked this pull request as ready for review March 21, 2023 20:13
and update docs on supported formats
@StefRe
Copy link
Copy Markdown
Contributor Author

StefRe commented Mar 31, 2023

Tests test_rebuild and test_error_messages seem to be a bit flaky: same failures as in #1116 (comment).

@larsoner larsoner merged commit 2c0f3bb into sphinx-gallery:master Mar 31, 2023
@larsoner
Copy link
Copy Markdown
Contributor

Wonderful @StefRe !

@StefRe StefRe deleted the enh/webp branch March 31, 2023 16:44
clrpackages referenced this pull request in clearlinux-pkgs/pypi-sphinx_gallery Apr 18, 2023
… to version 0.13.0

v0.13.0
-------

**Implemented enhancements:**

-  ENH: Create backreferences for default roles `#1122 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1122>`__ (`StefRe <https://github.com/StefRe>`__)
-  ENH raise error in check_jupyterlite_conf with unknown key `#1119 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1119>`__ (`lesteve <https://github.com/lesteve>`__)
-  ENH Add functionality to modify Jupyterlite notebooks based on their content `#1113 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1113>`__ (`lesteve <https://github.com/lesteve>`__)
-  ENH: Add support for WebP `#1111 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1111>`__ (`StefRe <https://github.com/StefRe>`__)

**Fixed bugs:**

-  ENH Clean-up code by early initialization of sphinx_gallery_conf `#1120 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1120>`__ (`lesteve <https://github.com/lesteve>`__)
-  FIX JupyterLite button links `#1115 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1115>`__ (`lesteve <https://github.com/lesteve>`__)
-  Fix thumbnail text formatting `#1108 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1108>`__ (`StefRe <https://github.com/StefRe>`__)

(NEWS truncated at 15 lines)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add WEBP to _KNOWN_IMG_EXTS

2 participants