Skip to content

Instantly share code, notes, and snippets.

@Kartones Kartones/imagemagick.md
Last active Mar 2, 2019

Embed
What would you like to do?
Imagemagick & ffmpeg commands

imagemagick

  • Nornalize all images of a folder converting them to jpgs with 90% quality (warning, removes original files):
rename 's/\.JPG$/\.jpg/' *.JPG
rename 's/\.JPEG$/\.jpg/' *.JPEG
rename 's/\.jpeg$/\.jpg/' *.jpeg
mogrify -format jpg *.png
mogrify -resize 1600x1280\> -quality 90 *.jpg
rm *.png
  • Generate 100x100 JPG thumbnails at a `/thumbs' subfolder from all JPG images of current folder, padding with black:
mkdir thumbs
mogrify -format jpg -quality 90 -path thumbs -unsharp 0x.5 -thumbnail 100x100 -background black -gravity center -extent 100x100 *.jpg
cd thumbs
rename 's/^/t_/' *.jpg

webp

  • setup:
sudo apt install webp
  • convert to png:
dwebp file.webp -o file.png
  • convert to jpg (using ImageMagick):
dwebp file.webp -o – | convert – file.jpg

ffmpeg

Animated GIF to MP4 video optimized for web:

ffmpeg -i animation.gif -b:v 0 -crf 40 -vf scale=600:-1 video.mp4

guetzli

Needs special binary

find . -type f -name "*.jpg" -exec guetzli --quality 85 {} {}.jpeg \;
find . -type f -name "*.jpg" -exec rm {} +
find . -type f -name "*.jpeg" | rename "s/\.jpeg$//"

If don't want to recurse directories:

find . -type f -maxdepth 1 -name "*.jpg" -exec guetzli --quality 85 {} {}.jpeg \;
rm *.jpg
rename "s/\.jpeg$//" *.jpeg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.