Skip to content

Instantly share code, notes, and snippets.

@indrekots
Created September 21, 2016 15:48
Show Gist options
  • Save indrekots/14fde2152031e5510a7da1e57367a440 to your computer and use it in GitHub Desktop.
Save indrekots/14fde2152031e5510a7da1e57367a440 to your computer and use it in GitHub Desktop.
How to mass update image files and fix their aspect ratio
  • 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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment