4

I have a few gigabytes of digital photos collected over the years in various directories. My current need is to look for photos in portrait mode as against landscape mode. I am trying to write a shell script with the help of the find and exif commands to see if I can get a list of images.

Portrait mode exif information shows that tag "Pixel Y Dimension" is larger than "Pixel X Dimension"

I have managed to get the right commands to get width and height of images:

exif -t 0xa002 image.jpg | grep Value | cut -d' ' -f 4 #Width
exif -t 0xa003 image.jpg | grep Value | cut -d' ' -f 4 #Height

How could I combine this with the find command so that I can find images where height is larger than width?

And, is there any way I can make it more generic - like find photos with certain date (in the exif data) or exif values?

Zanna
  • 72,471
  • It seems that it's much easier to write a simple python script than try to fit this task in bash (this article can help: https://www.blog.pythonlibrary.org/2010/03/28/getting-photo-metadata-exif-using-python/) – user502144 Aug 11 '17 at 21:43
  • @user502144 if you can write a python script to do this and post it as an answer, that would be awesome! – Zanna Aug 19 '17 at 21:48

2 Answers2

1

We can use a modified version of this answer: How to find all images with a certain pixel size using commandline?

find . -iname "*.jpg" -type f -exec identify -format '%w %h %i' '{}' \; | awk '$1<$2'
0

I think exiftool is better suited to this task. Rather than running a find and invoking a whole new instance of ImageMagick for each and every file, you can run a single exiftool command that will report all files in the current directory with height exceeding width:

exiftool -q -if '$ImageHeight > $ImageWidth' -p '$FileName' .

The dot at the end means "the current directory", you can substitute a different directory, or use a glob, like *.jpg to be more specific. You can also add -r option to recurse into subdirectories.