ImageMagick notes on image processing
Repository is here, official website and docs are here.
Remove metadata for privacy
magick input.jpg -strip output.jpg
Removing only location data, requires exiftool:
exiftool -gps:all= -o output.jpg input.jpg
# or
exiftool -gps:all= -overwrite_original input.jpg
Remove excess whitespace
Trim unused blank space, useful especially for logos:
magick input.png -strip -trim +repage output.png
Center crop
Can be used for fixed size blog post items.
magick input.jpg \
-strip \
-resize 800x600^ \
-gravity center \
-extent 800x600 \
-quality 82 \
-define webp:method=6 \
output.webp
Convert to WebP
Assets published on the web are better of if uploaded in WebP, providing lower sizes for the same quality compared to JPEG.
The webp:method flag below defines compression effort, taking values between 0 and 6. For non-realtime conversions, keeping it 6 provides the best compression effort.
magick input.jpg \
-strip \
-quality 86 \
-define webp:method=6 \
output.webp
Resize + convert:
magick input.jpg \
-strip \
-resize 1200x \
-quality 86 \
-define webp:method=6 \
-unsharp 0x0.75+0.75+0.008 \
output.webp
-unsharp 0x0.75+0.75+0.008 values are good with resizing along with web publishing.
Lossless:
magick input.png \
-strip \
-define webp:lossless=true \
output.webp
Batch:
for f in *.jpg; do
magick "$f" -strip -quality 86 -define webp:method=6 "${f%.jpg}.webp"
done