linux-图片压缩-ImageMagick
all
安装命令:yum install ImageMagick
=====================================================================================================================================================
Package Arch Version Repository Size
=====================================================================================================================================================
Installing:
ImageMagick x86_64 6.9.10.68-3.el7 base 2.3 M
Installing for dependencies:
OpenEXR-libs x86_64 1.7.1-7.el7 base 217 k
adobe-mappings-cmap noarch 20171205-3.el7 base 2.1 M
adobe-mappings-cmap-deprecated noarch 20171205-3.el7 base 114 k
adobe-mappings-pdf noarch 20180407-1.el7 base 703 k
cairo x86_64 1.15.12-4.el7 base 741 k
.......
SYNOPSIS
convert [input-option] input-file [output-option] output-file
convert 2019-12-30-17-03-10.png -resize 30% 2019-12-30-17-03-10-yasuo.png
convert 2019-12-30-17-03-10.png -resize 10% 2019-12-30-17-03-10-yasuo.png
magick convert rose.jpg -resize 50% rose.png
如果想降低图片的质量,可以用 convert 的 -quality 参数,质量值为 0-100 之间的数值,数字越大,质量越好,一般指定 70-80 ,基本上看不出前后的差别
大于200KB的图片都启用超级压缩
cp -a `find /xdata/xdocs/image -type f -mtime -2 -regex '.*\(jpg\|JPG\|png\|PNG\|jpeg\)' -size +200k` /xdata/low-image
cd /xdata/low-image && find . -type f -mtime -2 -regex '.*\(jpg\|JPG\|png\|PNG\|jpeg\)' -size +200k -exec convert -resize 10% {} {} \;
/xdata/low-image 存放低质量,超级压缩过后的图片(10倍压缩)
/xdata/xdocs/image 高清原图
grep -Rl "md-images" content/
[root@as4k low-xdocs]# grep -R "md-images" content/ | head
content/shell-script/all-shell-scripts.md:![](http://xdocs-images.all.xingyongsheng.top/2020-03-23-17-26-12.png)
content/shell-script/all-shell-scripts.md:![](http://xdocs-images.all.xingyongsheng.top/2020-05-05-10-40-56.png)
content/shell-script/循环.md:![](http://xdocs-images.all.xingyongsheng.top/2020-03-26-17-47-58.png)
content/shell-script/变量.md:![](http://xdocs-images.all.xingyongsheng.top/2020-03-25-10-29-07.png)
[root@as4k low-xdocs]# sed 's#md-images\.as4k\.top:8001#md-images\.as4k\.top:9001#g' content/shell-script/all-shell-scripts.md | grep md-images
![](http://xdocs-images.all.xingyongsheng.top/2020-03-23-17-26-12.png)
![](http://xdocs-images.all.xingyongsheng.top/2020-05-05-10-40-56.png)
sed 's#md-images\.as4k\.top:8001#md-images\.as4k\.top:9001#g' `grep -Rl "md-images" /xdata/low-xdocs/content`
sed 's#http://md-images\.as4k\.top:8001#https://gitee\.com/as4k/xdocs/raw/master/image#g' `grep -Rl "md-images" /xdata/low-xdocs/content`
sed 's#http://md-images\.as4k\.top:8001#https://gitee\.com/as4k/xdocs/raw/master/image#g' `grep -Rl "md-images" /xdata/xdocs/content`
https://gitee\.com/as4k/xdocs/raw/master/image/2019-12-10-10-45-02.png
sed -i 's#md-images\.as4k\.top:8001#md-images\.as4k\.top:9001#g' `grep -Rl "md-images" /xdata/low-xdocs/content`
cd /xdata/low-xdocs/image && find . -type f -regex '.*\(jpg\|JPG\|png\|PNG\|jpeg\)' -size +200k -exec convert -resize 10% {} {} \;