Image Compression tools via command line [closed]

Deadly 提交于 2019-11-28 13:48:06

问题


I'm searching best tool to compress images (png and jpeg) via command line.
After googling I found trimage which is good as it compresses both png and jepeg, but compression ratio is very poor in this case.

I came across jpeg-optimizer.com online tool which does the job way better than trimage. Can any one help to find the right tool for this.


回答1:


I'm using the following tools to perform lossless image compression:

  • pngcrush
  • gifsicle
  • jpegtran

For each of the programs, I've created two shortcuts:

  1. One that does the actual compression, and shows the file size of both files
  2. One that replaces the original file with the compressed one (If I'm satisfied, I'll do arrow-up, prefix my previous command with a "m", and press enter).

I've put this in my .bashrc:

# Image optimization tools
png() {
    pngcrush -brute "$1"{,.} && du -b "$1"{,.}
}
gif() {
    gifsicle -O "$1" -o "$1." && du -b "$1"{,.}
}
jpeg() {
    jpegtran "$1" > "$1." && du -b "$1"{,.}
}
# Just for easy access in history
mpng() {
    mv "$1"{.,}
}
mgif() {
    newsize=$(wc -c <"$1.")
    oldsize=$(wc -c <"$1")
    if [ $oldsize -gt $newsize ] ; then
        mv "$1"{.,}
    else
        rm "$1."
    fi  
}
mjpeg() {
    mv "$1"{.,}
}

Note: pngcrush -brute is very verbose. Redirect the output to /dev/null if you're not interested in the progress.




回答2:


  • Lossy PNG: pngquant2

  • Lossless PNG: AdvPNG (good and fast) or ZopfliPNG (slow, but best)

  • Lossless JPG: mozjpeg's jpegtran or jpegrescan

  • Lossy JPG: mozjpeg's cjpeg (try online) or imgmin

  • If you're running macOS: ImageOptim CLI




回答3:


If you are on Linux, try mogrify tool from the imagemagick suite

It is quite handy on command line.

Ex :

mogrify -resize 50% rose.jpg

mogrify -format jpg *.png


来源:https://stackoverflow.com/questions/19153122/image-compression-tools-via-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!