亲宝软件园·资讯

展开

Linux下压缩和优化jpg与png图片的方法

人气:0

jpegotim压缩jpg图片
安装jpegotim
如果你有epel yum源,使用如下命令即可


# yum install jpegoptim

压缩图片命令


# jpegoptim ttlsa.jpg

ttlsa.jpg 1425x823 24bit N JFIF  [OK] 1074449 --> 853514 bytes (20.56%), optimized.
可以看到ttlsa.jpg自动被压缩了20.56%。
再压缩一次


# jpegoptim ttlsa.jpg

ttlsa.jpg 1425x823 24bit N JFIF  [OK] 853514 --> 853514 bytes (0.00%), skipped.
图片已经被压缩过了,所以提示跳过,不需要在被压缩。
提供一个批量压缩的脚本


for i in /data/site/image.ttlsa.com/images/*.jpg; do jpegoptim $i; done

pngcrush优化PNG图片
项目地址:http://pmt.sourceforge.net/pngcrush/


# wget http://downloads.sourceforge.net/project/pmt/pngcrush/1.7.88/pngcrush-1.7.88.tar.gz
# tar -xzvf pngcrush-1.7.88.tar.gz
# cd pngcrush-1.7.88
# make
# cp pngcrush /usr/bin

pngcrush使用语法


usage: pngcrush [options except for -e -d] infile.png outfile.png
pngcrush -e ext [other options] file.png ...
pngcrush -d dir/ [other options] file.png ...
pngcrush -ow [other options] file.png [tempfile.png]
pngcrush -n -v file.png ...
options:
-bail (bail out of trial when size exceeds best size found
-bit_depth depth (deprecated)
-blacken (zero samples underlying fully-transparent pixels)
-brute (use brute-force: try 148 different methods)
........更多内容请自己看帮助......

pngcrush简单命令


pngcrush -brute -e "myimage_compressed.png" myimage.png
.........省略.....
Best pngcrush method = 123 (ws 15 fm 4 zl 9 zs 1) = 124820
for output to ttlsattlsa_new.png
(1.63% critical chunk reduction)
(1.63% filesize reduction)

CPU time decoding 1.560, encoding 7.640, other 0.030, total 9.230 sec.

批量优化PNG图片


pngcrush -brute -d "/data/site/image.ttlsa.com/images" *.png

加载全部内容

相关教程
猜你喜欢
用户评论