我的一位客户想要将他的图片转换为 WebP 格式,但经过一些测试后,我无法让 PageSpeed 像对其他格式那样调整它们的大小。
设置:
Rocky Linux 9:全新最小安装
Apache:2.4.57
ModPagespeed 版本:1.13.35.2
启用 PageSpeed 过滤器:
ah Add Head
cc Combine Css
jc Combine Javascript
gp Convert Gif to Png
jp Convert Jpeg to Progressive
jw Convert Jpeg To Webp
mc Convert Meta Tags
pj Convert Png to Jpeg
ws When converting images to WebP, prefer lossless conversions
db Debug
ec Cache Extend Css
ei Cache Extend Images
es Cache Extend Scripts
fc Fallback Rewrite Css
if Flatten CSS Imports
hw Flushes html
ci Inline Css
ii Inline Images
il Inline @import to Link
ji Inline Javascript
js Jpeg Subsampling
rj Recompress Jpeg
rp Recompress Png
rw Recompress Webp
ri Resize Images
cf Rewrite Css
jm Rewrite External Javascript
jj Rewrite Inline Javascript
cu Rewrite Style Attributes With Url
cp Strip Image Color Profiles
md Strip Image Meta Data
测试:
将图像转换为三种不同的格式:PNG,JPG 和 WebP。
将其添加到测试页面如下:
<img src="image.jpg" width="100" height="80"
<img src="image.png" width="100" height="80"
<img src="image.webp" width="100" height="80"
但是只有 JPG 和 PNG 可以调整大小,WebP 则不能。
从源代码中,使用?PageSpeedFilters=+debug
<img src="100x80ximage.jpg.pagespeed.ic.jWiwJkYbZC.webp" width="100" height="80" < div><!--Resized image http://example.com/image.jpg from 700x560 to 100x80--><!--The image was not inlined because it has too many bytes.-->
<img src="100x80ximage.png.pagespeed.ic.Pht8f0B3DS.webp" width="100" height="80" < div><!--Resized image http://example.com/image.png from 700x560 to 100x80--><!--Image http://example.com/image.png has no transparent pixels, is not sensitive to compression noise, and has no animation.--><!--The image was not inlined because it has too many bytes.-->
<img src="image.webp.pagespeed.ce.WmRDo9dlUQ.webp" width="100" height="80" < div><!----><!--The image was not inlined because it has too many bytes.-->
从/pagespeed_admin/message_history
Resized image `http://example.com/image.jpg' from 700x560 to 100x80
Shrinking image `http://example.com/image.jpg' (177955 bytes) to `http://example.com/100x80ximage.jpg.pagespeed.ic.jWiwJkYbZC.webp' (4010 bytes)
Resized image `http://example.com/image.png' from 700x560 to 100x80
Shrinking image `http://example.com/image.png' (809637 bytes) to `http://example.com/100x80ximage.png.pagespeed.ic.Pht8f0B3DS.webp' (4164 bytes)
Couldn't resize image `http://example.com/image.webp' from 700x560 to 100x80
Recompressing image `http://example.com/image.webp' (82120 -> 95886 bytes) doesn't save space; dropped.
概括:
- JPG 大小已调整,从 177KB 缩减至 4KB
- PNG 大小已调整,从 800KB 减小到 4KB
- WebP 仍为 82KB
有人遇到过类似的事情吗?我在网上找不到太多关于 PageSpeed 调整 WebP 文件大小的信息。
我是不是漏掉了什么?
提前致谢!