デジカメからPCに取り込んだ後、毎回WEBツールで圧縮するのは遅くて苦痛なので。
jpegoptim
インストール
$ sudo apt-get update $ sudo apt-get install jpegoptim
この操作後に追加で 31.7 kB のディスク容量が消費されます。
使い方
$ jpegoptim --help jpegoptim v1.4.1 Copyright (c) Timo Kokkonen, 1996-2014. Usage: jpegoptim [options] <filenames> -d<path>, --dest=<path> specify alternative destination directory for optimized files (default is to overwrite originals) -f, --force force optimization -h, --help display this help and exit -m<quality>, --max=<quality> set maximum image quality factor (disables lossless optimization mode, which is by default on) Valid quality values: 0 - 100 -n, --noaction don't really optimize files, just print results -S<size>, --size=<size> Try to optimize file to given size (disables lossless optimization mode). Target size is specified either in kilo bytes (1 - n) or as percentage (1% - 99%) -T<threshold>, --threshold=<threshold> keep old file if the gain is below a threshold (%) -b, --csv print progress info in CSV format -o, --overwrite overwrite target file even if it exists -p, --preserve preserve file timestamps -q, --quiet quiet mode -t, --totals print totals after processing all files -v, --verbose enable verbose mode (positively chatty) -V, --version print program version -s, --strip-all strip all markers from output file --strip-none do not strip any markers --strip-com strip Comment markers from output file --strip-exif strip Exif markers from output file --strip-iptc strip IPTC/Photoshop (APP13) markers from output file --strip-icc strip ICC profile markers from output file --strip-xmp strip XMP markers markers from output file --all-normal force all output files to be non-progressive --all-progressive force all output files to be progressive --stdout send output to standard output (instead of a file) --stdin read input from standard input (instead of a file)
使ってみる
$ jpegoptim -s ファイルパス
22%減量できた。ファイルは上書きされる。
/tmp/CIMG0777.jpg 2048x1536 24bit N JFIF [OK] 323586 --> 250993 bytes (22.43%), optimized.
品質90%。
$ jpegoptim -s ファイルパス -m 90
出力先パスの指定。
$ jpegoptim -s ファイルパス -m 90 -d 出力ディレクトリパス
findと組合せ
ディレクトリ配下すべてのJPGを圧縮する。
$ find ディレクトリパス -name '*.jpg' -o -name '*.JPG' -print | xargs jpegoptim -s
ファイル名の先頭がFIX_
のものは対象外。
$ find ディレクトリパス \( -name '*.jpg' -o -name '*.JPG' \) -not -name 'FIX_*' | xargs jpegoptim -s
参考
- https://morizyun.github.io/infrastructure/tool-optimize-jpeg-png.html
- https://parashuto.com/rriver/tools/automating-png-optimization-with-automator-and-pngquant#setting-optipng-and-imageoptim
- https://github.com/Leko/WEB-EGG/issues/123
補足
こちらで圧縮するとさらに半分以下になった。