How to use ImageMagick mogrify on file names contained in a text file?

1.2k views Asked by At

I want to run a mogrify command on images whose filenames are listed in a text file and I can't find a related answer on here.

Does anyone know how to do this please?

3

There are 3 answers

1
webbernaut On

Using the ImageMagick command line tool something like this. Below is how to glob a folder.

magick mogrify -resize 256x256 *.jpg

You can try a simple one liner in your terminal if using linux or unix OS (untested)

cat filename.txt | magick mogrify -resize 256x256
1
GeeMack On

To use a text list of images as input to ImageMagick you can just add a "@" at the beginning of the name of the text file like this...

mogrify -resize 480x @mylist.txt

If any of the filenames in the list have spaces in them, make sure they are enclosed in double quotes. So "mylist.txt" would look something like this...

"image one.jpg"
"image two.jpg"
"another image.jpg"
"and another one.jpg"
...

Edited to add:

The suggestion by webbernaut to cat and pipe the image list into the mogrify command should work if you modify it a bit. After the pipe, in the mogrify command you read in the image list with a "-", but ImageMagick still wants to work it like a text list, so the dash has to be preceded by an "@" like this...

cat mylist.txt | mogrify -resize 480x @-
0
bcag2 On

Thanks @GeeMack , I finally run :
du -hms *.jpg | sort -nr | head -n30 | awk '{print $2}' | mogrify -quality 70 -verbose @-
to compress 30 (head -n30) largest jpg files in my current folder