はじめに

圧縮率が高く、画質の劣化がほぼないと言われるWebp形式を使用したことがなかったので、その変換方法を調べる。

環境

1
2
Windows 10 Professional
WSL2 (Ubuntu 22.04 LTS)

webpコマンドのインストール

1
sudo apt-get install webp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  golang-1.18 golang-1.18-doc golang-1.18-go golang-1.18-src golang-doc golang-go golang-src pkg-config
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  freeglut3
The following NEW packages will be installed:
  freeglut3 webp
0 upgraded, 2 newly installed, 0 to remove and 12 not upgraded.
Need to get 160 kB of archives.
After this operation, 632 kB of additional disk space will be used.
Do you want to continue? [Y/n]

webpコマンドでjpeg画像を変換する

テスト画像を用意し、変換前と変換後で比較する。

テスト画像 jpeg形式

IMG_3960.jpeg

1
1.4M Aug 12 03:34 IMG_3960.jpeg

どうやら1.4Mあるらしい。

テスト画像 webp形式

下記のコマンドで変換する。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
$ cwebp IMG_3960.jpeg -o IMG_3960.webp

Saving file 'IMG_3960.webp'
File:      IMG_3960.jpeg
Dimension: 2048 x 1536
Output:    587950 bytes Y-U-V-All-PSNR 36.54 44.92 46.05   38.03 dB
           (1.50 bpp)
block count:  intra4:       9810  (79.83%)
              intra16:      2478  (20.17%)
              skipped:       520  (4.23%)
bytes used:  header:            392  (0.1%)
             mode-partition:  54517  (9.3%)
 Residuals bytes  |segment 1|segment 2|segment 3|segment 4|  total
    macroblocks:  |      32%|      16%|      20%|      32%|   12288
      quantizer:  |      36 |      29 |      22 |      15 |
   filter level:  |      11 |       6 |       5 |      18 |

できた?

1
2
1.4M Aug 12 03:34 IMG_3960.jpeg
575K Aug 12 03:39 IMG_3960.webp

かなり圧縮できていそう。
表示してみる。 IMG_3960.webp

ぱっと見だと、全然わからない…!
→下記とか使ってみたら比較の参考になりそう!
https://image-compare-viewer.netlify.app/

参考

おわりに

ブログで使用している画像が重いので、webp形式に変換したいなと思ったので調べた。
画像のリンクとか張り替えないといけないので面倒だけどやらないとなあ。