Build/Test Tools: Replace grunt-contrib-imagemin with maintained optimizers - #13562
manzoorwanijk wants to merge 7 commits into
Conversation
…timizers. `grunt-contrib-imagemin` was last released in March 2020, and it pins older majors of the packages that provide its binaries: the `gifsicle`, `jpegtran-bin` and `optipng-bin` versions it installs were all published in late 2018. Their macOS builds are x86_64 only, so `grunt precommit:image` fails on Apple Silicon unless Rosetta is installed. `imagemin:core` is now a local multi task built on `@napi-rs/image` (oxipng for PNG, MozJPEG for JPEG) and `@343dev/gifsicle`, which are actively released and ship prebuilt binaries for every supported platform. Images are optimized several at a time, and GIFs are left alone on the few platforms that have no prebuilt gifsicle binary. The results stay lossless. PNG keeps its exact pixels, JPEG is rewritten as progressive with optimized Huffman tables, and GIF is optimized with `gifsicle -O3 --interlace`. Images that come back larger are left untouched, which the previous task did not do. The dependency tree loses 330 packages and gains 3.
…images. The new optimizers find savings the previous ones left behind: 183 of the 284 images in scope shrink by 301,223 bytes in total, about 3 percent. Every changed file decodes to identical pixels. Some PNGs also drop from RGBA to grayscale with alpha, which is a lossless change of the stored color type.
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
lucatume
left a comment
There was a problem hiding this comment.
A refactor for the sake of maintainability.
I've not visually checked all the modified images, they are byte different, but pixel identical.
The odd one is src/wp-includes/images/smilies/icon_redface.gif that is not pixel identical, but the different pixels have alpha 0 (transparent).
Could something be done here (I'm thinking knobs in the imagemin task, to avoid changes to images that will not actually change?
…in`. The task is about 140 lines, which is more than belongs inline in the Gruntfile. It now lives in `tools/imagemin/task.js` and is registered with a single line. It also takes a `minSavedBytes` option, defaulting to 64. Optimizers keep finding a handful of bytes in images that are already optimal, and rewriting a versioned binary file for that is not worth it. With the option in place the task also settles in a single pass, where one PNG previously needed a second.
…imum. Sixty images saved between one and sixty-three bytes, so they are no longer rewritten. What remains is 123 images and 299,901 bytes, which is 99.6 percent of the savings from before.
That one is a palette reorder worth 4 bytes, so it is skipped now: the task takes a |
lucatume
left a comment
There was a problem hiding this comment.
Nothing blocking.
I've ran the task locally and verified the images using AI and all checks out.
From the mechanical point of view, this looks good to me.
grunt-contrib-imageminwas last released in March 2020, and thegifsicle,jpegtran-binandoptipng-binversions it pins were all published in late 2018. Their macOS builds are x86_64 only, sogrunt precommit:imagefails on Apple Silicon unless Rosetta is installed. This replaces the plugin with a local task built on optimizers that are still maintained.imagemin:coretask inGruntfile.jsis now local and uses@napi-rs/image(oxipng for PNG, MozJPEG for JPEG) and@343dev/gifsicle, both shipping prebuilt binaries for every supported platform.Alternatives considered
grunt-contrib-imagemin, and the newestgifsicle,jpegtran-binandoptipng-binreleases are from May 2022.imagemin6, so forcingimagemin7 or later breaks it.PATH: no dependencies to maintain, but every contributor installs them separately and nothing is pinned.Trac ticket: https://core.trac.wordpress.org/ticket/66118
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code, Codex
Model(s): Claude Opus 5
Used for: Comparing the replacements, writing the Grunt task, and verifying that every changed image decodes to identical pixels. Reviewed and edited by me.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.