[Peppermint] ロスレス圧縮コマンド optipng と jpegoptim をインストールする方法
前書き
ペパーミントでブログ用の画像の最適化、ロスレス圧縮するためのコマンドをインストールしたくなったので、その方法をメモとして残しておく。
僕がブログで使う画像はほとんど 100% PNG か JPEG なのでこの 2 つを最適化できるツールで、且つグーグルがおすすめしている画像圧縮ツールである optipng と jpegoptim をインストールすることにした。
optipng と jpegoptim の確認
どちらも apt でインストールできるので、インストール前にざっとどんなものかを確認しておく。
$ aptitude show optipng Package: optipng State: not installed Version: 0.6.4-1ubuntu0.14.04.1 Priority: optional Section: graphics Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Architecture: i386 Uncompressed Size: 207 k Depends: libc6 (>= 2.11), libpng12-0 (>= 1.2.13-4), zlib1g (>= 1:1.1.4) Description: advanced PNG (Portable Network Graphics) optimizer OptiPNG is a PNG optimizer that recompresses the image files to a smaller size. It losslessly reduces the bit depth, the color type and the color palette of the image, runs a suite of compression methods and strategies, and selects the compression parameters that yield the smallest output file. It also recognizes several external file formats like BMP, GIF, TIFF and PNM (PBM, PGM, PPM). Homepage: http://optipng.sourceforge.net/ $ aptitude show jpegoptim Package: jpegoptim State: not installed Version: 1.3.0-1ubuntu1 Priority: optional Section: universe/graphics Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Architecture: i386 Uncompressed Size: 66.6 k Depends: libc6 (>= 2.11), libjpeg8 (>= 8c) Description: utility to optimize jpeg files Jpegoptim can optimize/compress jpeg files. Program support lossless optimization, which is based on optimizing the Huffman tables. So called, "lossy" optimization (compression) is done by re-encoding the image using user specified image quality factor. Homepage: http://www.kokkonen.net/tjko/projects.html $
ではインストールしていきます。
$ sudo apt-get install optipng jpegoptim [sudo] password for nobi: Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: libspeechd2 linux-headers-3.16.0-37 linux-headers-3.16.0-37-generic linux-headers-3.16.0-46 linux-headers-3.16.0-46-generic linux-image-3.16.0-37-generic linux-image-3.16.0-46-generic linux-image-extra-3.16.0-37-generic linux-image-extra-3.16.0-46-generic Use 'apt-get autoremove' to remove them. The following NEW packages will be installed: jpegoptim optipng 0 upgraded, 2 newly installed, 0 to remove and 4 not upgraded. Need to get 92.2 kB of archives. After this operation, 273 kB of additional disk space will be used. Get:1 http://jp.archive.ubuntu.com/ubuntu/ trusty/universe jpegoptim i386 1.3.0-1ubuntu1 [14.2 kB] Get:2 http://jp.archive.ubuntu.com/ubuntu/ trusty-updates/main optipng i386 0.6.4-1ubuntu0.14.04.1 [78.0 kB] Fetched 92.2 kB in 0s (318 kB/s) Selecting previously unselected package jpegoptim. (Reading database ... 261409 files and directories currently installed.) Preparing to unpack .../jpegoptim_1.3.0-1ubuntu1_i386.deb ... Unpacking jpegoptim (1.3.0-1ubuntu1) ... Selecting previously unselected package optipng. Preparing to unpack .../optipng_0.6.4-1ubuntu0.14.04.1_i386.deb ... Unpacking optipng (0.6.4-1ubuntu0.14.04.1) ... Processing triggers for man-db (2.6.7.1-1ubuntu1) ... Setting up jpegoptim (1.3.0-1ubuntu1) ... Setting up optipng (0.6.4-1ubuntu0.14.04.1) ... nobi@OptiPlex-755 ~ $ echo $? 0 $ which optipng /usr/bin/optipng $ which jpegoptim /usr/bin/jpegoptim $
無事インストールできました。どちらも /usr/bin にインストールされています。
optipng の使い方
当ブログの過去記事に書いてありました♪
jpegoptim の使い方
僕は以下の使い方をすることになりそうです。
$ jpegoptim --strip-all -m70 --dest /home/oreore/Dropbox/Blog/image/optimize /home/oreore/Dropbox/Blog/image/Photo\ 2017-05-04\ 21\ 46\ 16.jpg
/home/oreore/Dropbox/Blog/image/Photo 2017-05-04 21 46 16.jpg 4032x3024 24bit N [OK] 3041951 --> 1398421 bytes (54.03%), optimized.
$
オプションを 3 つ使っています。
- –strip-all が画像にくっついている余計なデータを削る
- -m70 はクオリティを 70 % に下げて圧縮する
- –dest は圧縮されたファイルの保管先ディレクトリを指定する
です。
iPhone で撮った写真の画像でテストしたところ、3 MB の画像サイズが 1.4 MB まで小さくなりました。圧縮前と後で画像を見比べてみても大きな遜色はなかったので、クオリティを 70 % に指定する使い方でいいかと思っています。