Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Imagemagick & ffmpeg commands


  • 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
  • Fred's ImageMagick scripts

  • resize an image pixelating (without blending pixels): convert input.png -filter box -resize 400% output.png


  • setup:
sudo apt install webp
  • convert to png:
dwebp file.webp -o file.png
  • convert one image to jpg (using ImageMagick):
dwebp file.webp -o – | convert – file.jpg
  • convert all images from folder to jpg (using ImageMagick):
for f in *.webp; do dwebp "$f" -o - | convert - "${f%.webp}.jpg"; done


Animated GIF to MP4 video optimized for web:

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


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