#!/bin/bash
for fname in *.jpg; do
newfname=$(echo "${fname}" | sed "s/\.jpg$/_s.jpg/g")
w=`identify -format "%w" ${fname}`
h=`identify -format "%h" ${fname}`
if [ $w -lt $h ]; then
convert -geometry x86 "${fname}" "${newfname}"
else
convert -geometry 86 "${fname}" "${newfname}"
fi
done