Score:1

Batch convert multiple, specific images spread across dozens of folders

bm flag

I have a list of JPG files, each located in different folders on my command line only server, that I need converted to PNG.

I know the simple command to convert them one-by-one using mogrify. But I have around 300 images of different names spread across all different folders like so:

/home/user/dfp/app/roundtable/wp-content/uploads/2022/06/play.jpg
/home/user/dfp/app/roundtable/wp-content/uploads/2021/02/turn.jpg
/home/user/dfp/app/roundtable/wp-content/uploads/2020/01/up.jpg
/home/user/dfp/app/roundtable/wp-content/uploads/2022/09/down.jpg
/home/user/dfp/app/roundtable/wp-content/uploads/2021/01/left.jpg
etc etc

There is thousands of other images in each of the directories too, that I don't want altered at all. Just the specific files in my list.

Is there an easy watch to batch / bulk convert the list of images I have? I literally have a list of the images, like the example above, in a .txt file.

Score:1
hr flag

You can use a simple shell loop to read and process the filenames from the list file. In a bash shell for example:

while IFS= read -r file; do
  # your mogrify command on "$file"
done < path/to/listfile.txt

You can run it either in the interactive bash command line, or as a script with the #!/bin/bash shebang at the top.

Matt avatar
bm flag
Thanks, are those 3 separate commands I run in shell, or so I put those into a .sh file and run that? Please respond like I am a 5 year old.
hr flag
@Matt you can do either - see edit
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.