Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a directory full of images, some of which are portrait-sized instead of landscape-sized, and I want to open the portrait-sized ones with an image editor. I can run the imagemagick command identify and I get an output like something.jpg JPEG 1920x1255 1920x1255+0+0 8-bit DirectClass 159KB 0.000u 0:00.000. How can I have a script interpret this output, i.e. decide which is bigger, the 1920 or the 1255, and then run a command on it if it is?

share|improve this question

1 Answer 1

A combination of identify and bc seems to do the trick:

if [ $(identify -ping -format '%W/%H>1' filename.jpg | bc -l) -eq 1 ]; then
    echo "Landscape"
else
    echo "Portrait"
fi
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.