brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: magick mogrify -resize batch-resizes images, but overwrites them

Images
~/tips/tip-images-magick-mogrify-resize-batch

magick mogrify -path small -resize "1600x1600>" *.jpg

Resizes many images in one command, and with -path the originals stay untouched in their folder.

Phone photos are huge, and uploading fifty of them at full size is silly. ImageMagick resizes a whole folder in one command, but the tool in question has a nasty default.

mogrify overwrites the original files. The ImageMagick documentation says so plainly, and it is the difference with convert, which writes to a new file. So the safe variant comes first: write the results to another folder with -path.

mkdir small
magick mogrify -path small -resize "1600x1600>" *.jpg

The geometry 1600x1600 is a maximum width and height, and the aspect ratio is preserved. The > at the end makes it shrink only images that are larger than that, so small images are left alone. Put the geometry in quotes, because otherwise the shell treats > as a redirect and you create a strange file called 1600.

In ImageMagick 7 the command is magick mogrify. ImageMagick 6 has the plain mogrify command.

Only when you really want to replace the files, and you have a backup, run it without -path:

magick mogrify -resize "1600x1600>" *.jpg

The caveat is that -path needs an existing folder. Create it first, as above. Also, when you combine -path with a recursive find, every file lands in the same folder, so equal file names from different folders overwrite each other.

Further reading: ImageMagick: mogrify, ImageMagick: command-line processing

More Images tips montage *.jpg -tile 4x -geometry 300×300+4+4 sheet.jpg All Images tips (2) All topics

Link