Install gm
and pngquant
.
apt-get install gm pngquant
Generate a thumbnail.
You can replace -thumbnail
with -resize
for a clearer thumbnail that will result in a larger file size.
gm convert source_image.png -thumbnail 200x200 thumbnail_image.png
Generate a thumbnail while keeping horizonal aspect ratio.
gm convert source_image.png -thumbnail 200x thumbnail_image.png
Generate a thumbnail while keeping vertical aspect ratio.
gm convert source_image.png -thumbnail x200 thumbnail_image.png
Generate a thumbnail with a fix size and a fill-in background colour.
gm convert source_image.png -thumbnail 200x200 -background "#fff" -gravity center -extent 200x200 thumbnail_image.png
Optimise thumbnail
pngquant --ext=.png -f thumbnail_image.png
Batch optimise thumbnails
find . -name "*.png" -print0 | xargs -0 sudo pngquant --ext=.png -f