the following commands are the most common ImageMagick commands i use. when i used windows 11 i needed to add magick first (so for example magick mogrify -format jpg image.png) for the commands to work but i can use commands like mogrify, convert, etc directly in linux.

compression

i compress images so pages load faster and my site stays within the 1gb limit. the most common command i use is

mogrify -resize 800> -format jpg -quality 80 -strip *.heic

which i use for images on my microblog. my images usually end up a tenth of their original size. strip removes metadata such as the location where photos were taken. replace heic with the formats of the image you want to convert. if i find the result to be too low quality i use

for file in *.heic; do magick "$file" +sigmoidal-contrast 6.5,50% -filter Lanczos -distort Resize x800\> -unsharp 0.75x0.75+0.5+0.02 -sigmoidal-contrast 6.5,50% -format jpg -quality 90 -strip "${file%.*}.jpg"; done

which is much slower but adds a bit of sharpening and helps to preserve the depth of color.

extract first frame of a gif

within a folder, the following command

mogrify -format png *.gif[0]

extracts the first frame of every gif in the folder and writes it to a png which uses the same file name.

resizing pixel art animations

let's say we have a 1080p+ pixel art animation that was upscaled then had some sort of effects added to it in a video or animation program. those effects add a lot of grain and noise, making subsequent gifs very large. one trick to make it look more pixelated, reducing the file size, is to scale it down to its original dimension then scale it back up without anti-aliasing.

clipping videos and finding loop point

if starting with a video, clip a little outside the animation loop:

ffmpeg -ss 00:00:03 -to 00:00:15 -i ogvideo.mp4 -c copy clipped.mp4

then dump all frames to the folder "frames" in png format:

ffmpeg -i clipped.mp4 -q:v 2 frames/frame%04d.png

open the folder and manually delete images until the perfect loop point is found. start where there is a clear change in the animation (something moves after a long period of stillness, if something moves back and forth then the frame at the point of change, etc)

reducing frame rate

reduce frame rate by half by moving all odd or even number frames out of the working directory before converting to a gif:

mkdir even
mv -i *[24680].png even

or, if already have a gif called final.gif, can add option `-U final.gif seq -f "#%g" initialFrame skipBy finalFrame

gifsicle -U final.gif `seq -f "#%g" 0 3 599` -o final2.gif

resizing

imagemagick + gifsicle

resize all frame to be one-fifth their original size, then write to folder "small"

magick mogrify -path small -filter point -resize 20% frames/*.png

turn into a gif

magick -delay 1 -loop 0 frame*.png final.gif

use gifsicle scale with point sample to enlarge gifs

gifsicle --scale 5 --resize-method sample --loopcount --colors 256 -O3 --lossy=100 -d 1 -i final.gif > final2.gif

ffmpeg

resizing with ffmpeg seems to help with flickering + noise. from a series of images,

fmpeg -r 60 -start_number 61 -i frame%04d.png -c:v copy output.mkv

scale to be smaller

ffmpeg -i output.mkv -vf "zscale=384:216:filter=point" small.mkv

from here can use ezgif to convert to gif if want to add some brightness/contrast/etc adjustments. then use gifsicle to enlarge.

gifsicle small-ezgif.com-effects.gif --scale 5 --resize-method sample -O2 -d4 --lossy=40 > bigv4.gif

or convert from png

ffmpeg -start_number 61 -i nightbg/frame%04d.png -i palette2.png -lavfi "paletteuse,setpts=2*PTS" -y out.gif