optimize is the one you reach for when you don’t want to think about settings. Point it at a
directory, pick a preset, and it resizes and re-encodes everything inside — keeping each file’s
existing format unless you say otherwise.
Arguments
Options
Which preset to apply:
web, social, or email. See the table below for what each one does.Directory to write results into. Defaults to writing next to each input file — see the warning
below for why you usually want to set this.
A no-op — metadata is already stripped by default. Accepted so the flag doesn’t error if you
write it out of habit.
Write a JSON report of the results to this path. Same shape as
convert.Presets
Images smaller than the preset’s limit aren’t scaled up — the limit is a ceiling, not a target.
Two behaviours worth knowing
Extensions get normalised. Keeping the source format means keeping the format, not the spelling — a.jpg input comes back as .jpeg, because that’s the canonical extension for
image/jpeg. If you need the original spelling, use convert instead.
Changing format at the same time
--to overrides the keep-source-format behaviour, so you can resize and convert in one pass:
Checking first
Becauseoptimize touches a whole directory, --dry-run is worth the habit: