ragouel
ragouel

Reputation: 169

How to make ImageMagic identify accept input from a pipe?

Trying to pipe list of images from find to identify and I get no output.

Using this command, I get no results.

find . -iname "*.jpg" -type f | identify -format '%w:%h:%i' 

However, if I use this command, which doesn't use a pipe but instead uses find's -exec option it works normally.

find . -iname "*.jpg" -type f -exec identify -format '%w:%h:%i\n' '{}' \;

Does anyone know why this is happening and how to use pipe properly instead of find -exec?

Upvotes: 2

Views: 859

Answers (3)

Mark Setchell
Mark Setchell

Reputation: 207758

Your first command, namely this:

find . -iname "*.jpg" -type f | identify -format '%w:%h:%i'

doesn't work because identify expects the filenames as parameters, not on its stdin.


If you want to make identify read filenames from a file, you would use:

identify -format '%w:%h:%i\n' @filenames.txt

If you want to make identify read filenames from stdin, (this is your use case) use:

find . -iname "*.jpg" -type f | identify -format '%w:%h:%i\n' @-

If you want to get lots of files done fast and in parallel, use GNU Parallel:

find . -iname "*.jpg" -print0 | parallel -0 magick identify -format '%w:%h:%i\n' {}

Upvotes: 2

fmw42
fmw42

Reputation: 53164

This works for me:

identify -format '%w:%h:%i\n' $(find . -iname "*.jpg")


Note: I have added \n so that each image will list on a new line.

Upvotes: 2

ragouel
ragouel

Reputation: 169

Figured it out, I needed to use xargs

find . -iname "*.jpg" -type f | xargs -I '{}' identify -format '%w:%h:%i\n' {}

the brackets '{}' are used to represent the file array.

Upvotes: 2

Related Questions