Page 1 of 1

Modifying a list of images

Posted: 2018-09-24T23:58:40-07:00
by harryhermit
Hi,

I'm using imagemagick in windows and I use this script at the command line:

magick *.jpg -set filename:f "%[t]" -background white -gravity center ^
-extent %[fx:max(w,h)]x%[fx:max(w,h)] -quality 100 "%[filename:f].jpg"

It works great for modifying images in the folder I navigate to, but I need to modify specific images nested in hundreds of different folders. I have a list of these images and their locations in a txt file. Is there a way to run this script in batch for these specific images in the txt file?

Re: Modifying a list of images

Posted: 2018-09-25T03:20:58-07:00
by snibgo
In Windows, use a "for" loop to read the text file. See "help for".

Re: Modifying a list of images

Posted: 2018-09-25T07:09:11-07:00
by GeeMack
harryhermit wrote: 2018-09-24T23:58:40-07:00I have a list of these images and their locations in a txt file. Is there a way to run this script in batch for these specific images in the txt file?
If the text list has full path file names, you can have IM read that list by preceding it with "@". Then when setting the file name in your command, use "%[d]" to indicate the directory path. This command should do pretty much what you're looking for...

Code: Select all

magick @list.txt -set filename:f "%[d]\\%[t]" -background white -gravity center ^
   -extent %[fx:max(w,h)]x%[fx:max(w,h)] -quality 100 "%[filename:f].jpg"
Some issues to consider...

First, IM will try to read in all the files in "list.txt" before doing any processing, so if that will exhaust your memory resources you'd be better off building a command using a "for" loop as mentioned by snibgo above.

Also, I'd make sure to use full path filenames in the list, not relative paths. Note that setting the filenames for Windows requires you to escape the backslash "\" with another backslash like "%[d]\\%[t]".

If there are any spaces in any of your file or path names, you need to double quote those names in the text file otherwise IM will try to read the parts as if they're separate file names.

And as always, when running IM commands in a BAT script, make sure to double all the percent signs "%%" on everything except Windows own variables like "%TIME%".

Re: Modifying a list of images

Posted: 2018-09-25T10:38:16-07:00
by harryhermit
Thanks for the help! I got it to run using this batch:

for /F "tokens=*" %%A in (images.txt) do magick %%A -set filename:f "%%[t]" -background white -gravity center ^
-extent %%[fx:max(w,h)]x%%[fx:max(w,h)] -quality 100 "%%[filename:f].jpg"