Page 1 of 1

need to auto crop

Posted: 2010-09-10T18:05:11-07:00
by graysky
I have a pretty specific need to mass-process a ton of images in a directory tree. The major problem I'm having is that the source images have, for the most part, different aspect ratios. Why? People did a bunch of silly freehand crops on perfectly good images! Anyway, I would like to batch process as follows:

Crop the source images such that each outputted image will have an aspect ratio of either 4:3 if landscape or 3:4 if portrait losing the minimum number of pixels in the process. I understand that there is no way to accurately know what would make the most pleasing crop from a gravity perspective (starting from the top, left, right, etc.), but I don't care given the large number of photos I'm dealing with in this scenario.

Suggestions are greatly appreciated.

Re: need to auto crop

Posted: 2010-09-10T19:46:59-07:00
by fmw42
see my scripts, aspect and aspectpad. They may be of help. But you will need to write a wrapper script to traverse your directory tree. My scripts work on one image at a time.

Re: need to auto crop

Posted: 2010-09-11T01:56:51-07:00
by graysky
This is great. Here's what I came up with to do my resizing. Also thank you kindly for the emails with those excellent suggestions, and for your scripts.

Code: Select all

#!/bin/bash

if [ ! -d processed_images ]; then
 mkdir processed_images
fi

for PIC in `ls *.{jpg,JPG,jpeg,JPEG}`; do
NAME=`echo ${PIC} | sed 's/.jpg//' | sed 's/.JPG//' | sed 's/.jpeg//' | sed 's/.JPEG//'`
 test=`convert ${PIC} -format "%[fx:(w/h)>=1?1:0]" info:`

 if [ $test -eq 1 ]; then
  echo ${PIC} "is landscape... making thumbnail and image"
  aspect.sh 150x113 -m crop ${PIC} ./processed_images/${NAME}a.jpg
  aspect.sh 600x450 -m crop ${PIC} ./processed_images/${NAME}b.jpg
 else
  echo ${PIC} "is portraitn... making thumbnail and image"
  aspect.sh 113x150 -m crop ${PIC} ./processed_images/${NAME}a.jpg
  aspect.sh 450x600 -m crop ${PIC} ./processed_images/${NAME}b.jpg
 fi
done