转换前:
[root@online home]# du -sh /var/www/html/data/attachment/forum/
164M /var/www/html/data/attachment/forum/
[root@online home]# du -sh /var/www/html/data/attachment/album/
18M /var/www/html/data/attachment/album/
转换后
[root@online home]# du -sh /var/www/html/data/attachment/forum/
106M /var/www/html/data/attachment/forum/
[root@online home]# du -sh /var/www/html/data/attachment/album/
9.1M /var/www/html/data/attachment/album/
转换脚本,定时任务执行。
#!/bin/bash
USER="www"
FORUM="/var/www/html/data/attachment/forum"
ALBUM="/var/www/html/data/attachment/album"
for id in `find $FORUM -type f |xargs file |grep "image data" |grep -v "GIF" |awk -F':' '{print $1}'`;do
echo $id
webp="${id}.webp"
convert $id $webp
mv $webp $id
done
for id in `find $ALBUM -type f |xargs file |grep "image data" |grep -v "GIF" |awk -F':' '{print $1}'`;do
echo $id
webp="${id}.webp"
convert $id $webp
mv $webp $id
done
chown -R $USER:$USER $FORUM
chown -R $USER:$USER $ALBUM
依赖软件
ImageMagick
libwebp-tools
|