#58996 closed enhancement (fixed)
Expand "imagemin" Grunt task to cover default themes
Reported by: | azaozz | Owned by: | swissspidy |
---|---|---|---|
Milestone: | 6.5 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Build/Test Tools | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
WordPress uses Imagemin in Grunt to minify new images. However it seems the last time new (non svg) images were added was 7 years ago. See:
https://core.trac.wordpress.org/browser/trunk/src/wp-includes/images?order=date&desc=1
https://core.trac.wordpress.org/browser/trunk/src/wp-admin/images?order=date&desc=1
Seems the imagemin
task in Grunt has been redundant for a long time. Perhaps would be good to retire it and go back to minifying new images "by hand" before committing them, if non-svg images are ever added again.
Attachments (1)
Change History (14)
#2
in reply to:
↑ 1
@
14 months ago
Replying to desrosj:
It's true that within those two directories images have not been added, but there have been lots of images added to the
wp-content/themes
directory. I think it's probably worth looking at expanding theimagemin
task to include themes.
I agree, it seems like the task would still be beneficial for themes.
#3
@
12 months ago
- Milestone changed from 6.4 to 6.5
I agree with @desrosj that we should expand this rather than eliminate it.
However, I do think this might be better for 6.5 as we are now in RC. Feel free to move back to 6.4 if someone feels strongly otherwise.
#4
@
9 months ago
- Keywords commit added; 2nd-opinion removed
- Owner set to swissspidy
- Status changed from new to accepted
#5
@
9 months ago
- Summary changed from Consider removing the "imagemin" task from Grunt to Expand "imagemin" Grunt task to cover default themes
#8
@
9 months ago
It shouldn‘t have 👀 At least I wouldn‘t expect this script to do that.
Do you have an example of an image that got bigger?
Maybe we need to tweak a config or update a dependency somewhere.
#9
@
9 months ago
The diff was more apparent to me in the terminal when I ran svn update, but I don't know how to view a diff with file sizes listed here on trac.
https://core.trac.wordpress.org/browser/trunk/src/wp-content/themes/twentyeleven/images/headers/chessboard.jpg?rev=57322
New File size: 52.3 KB
https://core.trac.wordpress.org/browser/trunk/src/wp-content/themes/twentyeleven/images/headers/chessboard.jpg?rev=46586
Old File size: 51.3 KB
https://core.trac.wordpress.org/browser/trunk/src/wp-content/themes/twentytwentytwo/assets/images/ducks.jpg?rev=57322
New File size: 364.3 KB
https://core.trac.wordpress.org/browser/trunk/src/wp-content/themes/twentytwentytwo/assets/images/ducks.jpg?rev=52651
Old File size: 357.9 KB
#10
@
9 months ago
@swissspidy hello. Looking at the commit on GitHub together with @SergeyBiryukov and @poena we did notice most of the images actually have a _larger_ size now.
See https://github.com/WordPress/wordpress-develop/commit/5cd843e235ba9fa40cf716c7e52abc823a48ba7c
I'm guessing that also means the larger images have now a _lower_ quality because the added pixels are the result of some interpolation.
We're all for automating this process but ideally it should make sure to not make images size bigger :)
#11
@
9 months ago
Thanks, very helpful!
I'm guessing that also means the larger images have now a _lower_ quality because the added pixels are the result of some interpolation.
imagemin is supposed to do lossless compression according to the documentation, so quality shouldn't decrease.
I am now trying npm run grunt imagemin
again with different configuration and even with mozjpeg but weirdly enough I now can't get it to process those files again 🤔
Of course I could manually optimize them again but then what's the point.
#12
@
9 months ago
imagemin is supposed to do lossless compression according to the documentation, so quality shouldn't decrease.
Maybe I wasn't clear.
When the image size actually increases, that means that some pixels are _added_ to the image (which is already optimized, it's not the original high-quality image). That means imagemin actualy 'rebuilds' some pixels adn adds them to the image, as a result of some interpolation process. These 'rebuilt' pixels can't in any way _improve_ the quality of the image.
I'm not sure that relying on "by hand" is the best path here. Even for experienced contributors and committers, it's very easy to forget steps like this when it's not often images are added.
It's true that within those two directories images have not been added, but there have been lots of images added to the
wp-content/themes
directory. I think it's probably worth looking at expanding theimagemin
task to include themes.I attached a patch that expands to theme directories, and running
npm run grunt precommit:image
results in 106 images being minified, and seems to save ~1KB per image within the theme.The fact that the images within themes can be further minified is a good example of forgetting to manually perform minifying prior to committing.