optipngとjpegoptimで画像を最適化

/ Web / Comment[0]
Googleアド先生に勧められたので使ってみました。

  • optipng
  • pngの可逆圧縮による最適化ツール
  • jpegoptim
  • JPEGのExifなどのテキスト情報を取り除き、圧縮レベルを調節するツール


インストールはapt-getでおk
$ sudo apt-get install jpegoptim optipng


optipngでpngを可逆圧縮


$ optipng --help
OptiPNG 0.6.4: Advanced PNG optimizer.
Copyright (C) 2001-2010 Cosmin Truta.

Synopsis:
optipng [options] files ...
Files:
Image files of type: PNG, BMP, GIF, PNM or TIFF
Basic options:
-?, -h, -help show this help
-o <<evel> optimization level (0-7) default 2
-v verbose mode / show copyright and version info
General options:
-fix enable error recovery
-force enforce writing of a new output file
-keep keep a backup of the modified files
-preserve preserve file attributes if possible
-quiet quiet mode
-simulate simulation mode
-snip cut one image out of multi-image or animation files
-out <file> write output file to <file>
-dir <directory> write output file(s) to <directory>
-log <file> log messages to <file>
-- stop option switch parsing
Optimization options:
-f <filters> PNG delta filters (0-5) default 0,5
-i <type> PNG interlace type (0-1) default <input>
-zc <levels> zlib compression levels (1-9) default 9
-zm <levels> zlib memory levels (1-9) default 8
-zs <strategies> zlib compression strategies (0-3) default 0-3
-zw <window size> zlib window size (32k,16k,8k,4k,2k,1k,512,256)
-full produce a full report on IDAT (might reduce speed)
-nb no bit depth reduction
-nc no color type reduction
-np no palette reduction
-nx no reductions
-nz no IDAT recoding
Optimization details:
The optimization level presets
-o0 <=> -o1 -nx -nz
-o1 <=> [use the libpng heuristics] (1 trial)
-o2 <=> -zc9 -zm8 -zs0-3 -f0,5 (8 trials)
-o3 <=> -zc9 -zm8-9 -zs0-3 -f0,5 (16 trials)
-o4 <=> -zc9 -zm8 -zs0-3 -f0-5 (24 trials)
-o5 <=> -zc9 -zm8-9 -zs0-3 -f0-5 (48 trials)
-o6 <=> -zc1-9 -zm8 -zs0-3 -f0-5 (120 trials)
-o7 <=> -zc1-9 -zm8-9 -zs0-3 -f0-5 (240 trials)
The libpng heuristics
-o1 <=> -zc9 -zm8 -zs0 -f0 (if PLTE is present)
-o1 <=> -zc9 -zm8 -zs1 -f5 (if PLTE is not present)
The most exhaustive search (not generally recommended)
[no preset] -zc1-9 -zm1-9 -zs0-3 -f0-5 (1080 trials)

helpを見てみると色々と細かいオプションを指定できるようですが、いちいちオプションを指定していくのは面倒です。
なのであらかじめ定義されているエイリアス「-o1~7」を指定します。
-o1が一番ゆるい圧縮、-o7が一番きつい圧縮って感じでしょうか。

-o7でいざ圧縮 -outオプションで出力ファイルを指定しない場合はソースファイルに上書きされます。
$ optipng -o7 default_temp_201312.png

** Processing: /storage/default_temp_201312.png
300x2000 pixels, 4x8 bits/pixel, RGB+alpha
Reducing image to 8 bits/pixel, 252 colors (169 transparent) in palette
Input IDAT size = 14326 bytes
Input file size = 14420 bytes

Trying:
zc = 9 zm = 9 zs = 0 f = 0 IDAT size = 5751

Selecting parameters:
zc = 9 zm = 9 zs = 0 f = 0 IDAT size = 5751

Output IDAT size = 5751 bytes (8575 bytes decrease)
Output file size = 6794 bytes (7626 bytes = 52.88% decrease)

なんということでしょう。52.9%も圧縮されているではありませんか。しかも無劣化。


jpegoptimでJPEG画像を圧縮、Exif,コメントなどの情報を削除


--strip-allオプションによりExifやコメントなどの情報を削除、-mオプションで画像のクオリティ(%)を指定できます。
$ jpegoptim --strip-all -m80 20140624133941.jpg
20140624133941.jpg 3920x2940 24bit  [OK] 2451191 --> 1211969 bytes (50.56%), optimized.

なんということでしょう。50%も圧縮できました。クオリティは80%と若干高めなので劣化はそれほど気になりません。

-mオプションをつけずに--strip-allオプションだけで実行すればExif,コメント情報のみを削除するという使い方もできます。

画像を上げる前の一手間としてこのコマンドを実行することで
ページも軽くなりますし、Exifの余計な情報を公開せずに済むのでプライバシー面でも安心です。
関連記事

コメント

:
:
:
:
:
管理人のみ表示を許可