网页的大小决定网站的打开速度,网页越小速度越快,用户体验越好。网页中占用空间最大的为图片,本文提供图片图片格式转化和压缩的方法。
格式转化
convert png to jpg
for file in `ls | grep ".png"`; do newfile=`echo $file | sed 's/.png//g'`; sips -s format jpeg $file --out ./$newfile.jpg; mv $file /tmp; done
压缩
for file in `ls | grep -e "tuya.png" -e "tuya.jpg"`; do newfile=`echo $file | sed 's/-tuya//g'`; mv $file $newfile; done
#!/bin/bash
set -ex
for suffix in png jpg; do
for file in `find . -type f -name "*.${suffix}"`; do
tmpfile=$(echo ${file} | sed "s/.$suffix/.t1m2p3.$suffix/g")
mv ${file} ${tmpfile}
format=${suffix}
if [ "$suffix" == "jpg" ]; then
format="jpeg"
fi
sips -s format ${format} ${tmpfile} --out ${file}
rm ${tmpfile}
done
done