3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

私はローカルで再帰的に画像を圧縮したかったメモ

Last updated at Posted at 2018-09-28

使ったもの

  • Mac(homebrew入り)
  • pngquant・・・png圧縮するやつ。有名らしい
  • mozjpeg・・・jpeg圧縮するやつ。mozillaのやつとgoogleのやつで悩んだけどmozillaのほうが良さそうなので

インストール

$ brew install pngquant mozjpeg
$ echo 'export PATH="/usr/local/opt/mozjpeg/bin:$PATH"' >> ~/.bash_profile
$ source ~/.bash_profile

ワンライナーでいまのディレクトリ以下を捜索して上書きしてくれるやつ

png

find ./ -name "*.png" | xargs -L1 -P8 pngquant --ext .png --speed 1 --skip-if-larger --force

jpg

mozjpegにはいくつかのbinがあるのですがワンライナーで書きやすそうなjpegtranを利用しました。

find . -name "*.jpg" | xargs -I@ -P4 jpegtran -copy none -optimize -outfile @ @

実際は他のコマンドを使ってqualityを指定した圧縮をしたほうが良いのかもですが、とりあえずロスレス圧縮しただけ。

終わり。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?