- Find all image files
find . -type f -name "*.jpg" > images
- Determine if image file is portrait or landscape
find . -type f -name "*.jpg" -exec sh -c "identify -ping -format '%W/%H>1' {} | bc -l" \; > aspect
- Paste the results together
paste images aspect > image_aspect
-
Download aspectcrop and make it executable.
-
Make sure all portrait files have an aspect ratio of 2:3
cat image_aspect | awk '$2 == "0"' | awk '{print $1}' | xargs -l bash -c './aspectcrop -a 2:3 $0 ../fixed/$0'
- Make sure all landscape files have an aspect ratio of 3:2
cat image_aspect | awk '$2 == "1"' | awk '{print $1}' | xargs -l bash -c './aspectcrop -a 3:2 $0 ../fixed/$0'