Skip to content

Add WEBP to _KNOWN_IMG_EXTS #1055

@FirefoxMetzger

Description

@FirefoxMetzger

I was wondering if we could add "webp" to the list of known image extensions that scrapers may produce. The change would be a one-liner in:

_KNOWN_IMG_EXTS = ('png', 'svg', 'jpg', 'gif')

which would have to be changed to:

_KNOWN_IMG_EXTS = ('png', 'svg', 'jpg', 'gif', 'webp')

The background for this is that I have recently built a custom scraper for the gallery of a rendering engine. This works great, but now I would like to add animations to some of the examples. Technically, GIF could work but the limitation of 256 colors really shows when you have complex shadows or gradients and that may send the wrong message with respect to the project's rendering capabilities. (It's wgpu/vulkan based, so it has all the bells and whistles and 265 colors don't do this justice.)

WEBP would be a nice alternative here, because it, too, has wide browser support, better compression than GIF and - most importantly - uses YUV420 instead of 8-bit palette RGB as a colorspace. The only thing "preventing" me from using it is sphinx-gallery, which currently hardcodes supported file extensions...

As a current workaround I am monkey-patching _KNOWN_IMG_EXTS in the _get_sg_image_scraper like so:

def _get_sg_image_scraper():
    # hack webp as supported extension
    import sphinx_gallery.scrapers
    sphinx_gallery.scrapers._KNOWN_IMG_EXTS += ("webp",)

    ...

This works, but it would be much nicer if I wouldn't have to rely on a hack that modifies private variables from an upstream project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions