The order of my options changes the result
ImageMagick options split into settings that configure what comes after, and operators that act immediately. Understanding the difference explains most confusing results.
You moved a flag and the output changed completely, or a flag appeared to do nothing at all. This is the concept that explains most confusing ImageMagick behaviour, and it is barely mentioned in the documentation's introduction.
Two kinds of option
Settings — configure what comes after
-density, -size, -background, -gravity, -fill, -font, -pointsize, -delay, -loop, -quality, -channel, -compose, -bordercolor, -filter.
These change state. They affect images read or drawn after them. Placed too late in the command, they have no effect at all.
Operators — act immediately
-resize, -crop, -rotate, -flip, -composite, -annotate, -border, -extent, -trim, -blur, -negate.
These act on the images already loaded, in the order written, left to right.
Where this bites
-density before the PDF
magick -density 300 in.pdf out.png # correct — 300 DPI render
magick in.pdf -density 300 out.png # wrong — rendered at 72, then tagged 300
The second produces a blurry image with misleading metadata. This is the single most common ordering mistake.
-size before a generated source
magick -size 800x600 xc:white out.png # correct — 800x600
magick xc:white -size 800x600 out.png # wrong — 1x1 pixel
-background before -extent
magick in.jpg -background white -gravity center -extent 1200x1200 out.jpg # correct
magick in.jpg -gravity center -extent 1200x1200 -background white out.jpg # padding is not white
-delay before the frames
magick -delay 8 -loop 0 frame_*.png out.gif # correct
magick frame_*.png -delay 8 -loop 0 out.gif # timing ignored
Operators run in sequence
magick in.jpg -resize 400x400 -crop 200x200+0+0 +repage out.jpg
magick in.jpg -crop 200x200+0+0 +repage -resize 400x400 out.jpg
The first scales to 400×400 then takes a 200×200 corner. The second takes a 200×200 corner of the original and scales it up to 400×400. Both are valid; they produce entirely different images.
Settings persist until changed
magick in.jpg -gravity south -annotate +0+20 'Bottom' \
-gravity north -annotate +0+20 'Top' out.jpg
The first -gravity stays in force until the second replaces it. Forgetting to reset a setting is a common source of "why is my second annotation in the wrong place".
Some settings are cleared with the plus form: -channel A then +channel, -repage then +repage. Generally minus sets and plus unsets.
Parentheses scope the sequence
magick in.jpg '(' logo.png -resize 20% ')' -gravity southeast -composite out.jpg
The -resize 20% inside the parentheses applies only to logo.png. Without them it would apply to whatever images are currently loaded — which here would be both.
A rule of thumb
Read the command left to right as a sequence of instructions to a machine that holds a stack of images. Ask of each flag: is this describing how to do the next thing, or is it doing something now? Settings go before the thing they describe. Operators go where you want them to happen.