ImageMagick @filename referencing with multiple outputs

Viewed 658

I see in ImageMagick's documentation that I can use something like magick @myfiles.txt to send multiple filenames (in my case I can't use globbing since they're random) to input, but the only example available combines them into a single output.

Is there a way to output separate files for each input using this functionality? If not, how would one achieve this in Powershell? Something like Get-content filenames.txt | ForEach-Object {magick}?

2 Answers

I haven't tested this so make a COPY of a few files in a temporary directory before trying.

Make an output directory called RESULTS and resize a bunch of files listed in files.txt

mkdir RESULTS
magick mogrify -resize 64x64 -path RESULTS @files.txt

Be very careful with mogrify, if you don't specify -path it will overwrite a lot of files very, very quickly.

If your ImageMagick command is simple and just one image in the command line, then you can use magick mogrify to process each image in the folder. Otherwise, you can use -set filename to use the file names for multiple input/output images in a magick command line. However, if you have too many input images, then you will run out of RAM, since ImageMagick loads all the input images at one time in the magick command. magick mogrify reads them one at a time. For a magick command, you can do

magick @myfiles.txt -set filename:fn "%t" <commands> +adjoin "%[filename:fn]_processed.suffix"

The %t gets the name of the file without the suffix. See https://imagemagick.org/script/escape.php

Also see mogrify at https://archive.imagemagick.org/Usage/basics/#mogrify

Sorry, I do not know Powershell.

Related