具有图像魔术的图像优化,以提高我的WordPress网站上的页面速度



我在网站的页面速度(WordPress/avada主题(上遇到问题,大多数问题归功于未优化的图像。我做了一些研究并使用图像魔术。

这是GT Metrix的报告:

https://gtmetrix.com/reports/www.tinkertravels.com/ac0dmcte

我有此脚本用于转换我的图像:

convert /Users/james/Desktop/image-magick/santorini.jpg -sampling-factor 4:2:0 -strip -quality 75 -resize 700x466! -interlace JPEG -colorspace RGB -background white -flatten /Users/james/Desktop/image-magick/final/santorini-opt.jpg 

但是,我想将散装图像从一个文件夹(输入(转换为另一个文件夹(输出(,然后在每个图像的末尾添加_Output?

目前脚本一次使用相同名称的一个图像,这不是理想的。

关于如何更改上述脚本执行此操作的任何帮助将是很棒的。我希望一旦我用这些替换图像,我的页面速度就会增加并停止抱怨图像!

谢谢

shell脚本是可能的。在设置任何设置或操作员之前,您应该剥离。如果在当前的ImageMagick上,请使用-colorspace SRGB(如果需要非线性颜色和RGB(,如果需要线性颜色。如果在非常旧的IM版本上,请逆转它们。

cd path2/inputdirectory
list=$(ls *.jpg)
for img in $list; do
inname=$(convert -ping $img -format "%t" info:)
convert $img -strip -colorspace RGB -resize 700x466! -background white -flatten -interlace JPEG -sampling-factor 4:2:0 -quality 75 path2/outputdirectory/${inname}.jpg
done

最新更新