Page 1 of 1

Help me square some images ($100)

Posted: 2014-04-15T12:35:14-07:00
by mpascal
I have a collection of ~30,000 images (mostly photos) in a directory tree.
There are a few hundred images there (jpgs and pngs) that I need to square.
How to find them?
Find all images with prefix "hide" and suffix "hero" whose width is at least twice the height
What to do with them?
Add black padding on top and bottom so that they become square.
Sample image we are looking for
https://www.dropbox.com/s/ovz7fb9njwxhn ... G_hero.jpg
Sample result
https://www.dropbox.com/s/gxwl4iekksko6 ... d_hero.jpg

I've seen this http://www.imagemagick.org/Usage/thumbnails/#square
but it's still over my head and I could use your assistance.

Thank you!
Marino

Re: Help me square some images ($100)

Posted: 2014-04-15T12:41:59-07:00
by Bonzo
You need to specify your platform as you will need a shell or batch script and that will be the first thing you are asked; along with you IM version.

Re: Help me square some images ($100)

Posted: 2014-04-15T12:50:41-07:00
by mpascal
Centos, ImageMagick 6.8.1-0 2012-12-27 Q16

Re: Help me square some images ($100)

Posted: 2014-04-15T14:14:31-07:00
by dlemstra
The following script should do the trick:

Code: Select all

#!/bin/sh
FILES=`ls /path/to/files/hide*hero.*`
for FILE in ${FILES}; do
WIDTH=`identify -format %w "$FILE"`
DOUBLE_HEIGHT=`identify -format %[fx:h*2] "$FILE"`
if [ $DOUBLE_HEIGHT -lt $WIDTH ]; then
  mogrify -background black -gravity center -extent ${WIDTH}x${WIDTH} $FILE $FILE.jpg
fi
done

Re: Help me square some images ($100)

Posted: 2014-04-16T11:28:10-07:00
by mpascal
Thank you, Dirk.
Marino