#!/bin/sh

# depends on imagemagick.

prepend_image_size() {
  path="$1"
  size=$(identify -format '%h' "$path")p
  new_path="$(dirname "$path")/$size.$(basename "$path")"

  if test ! -e "$new_path"
  then
    mv "$path" "$new_path"
  fi
}

for a in "$@"
do
  if test -f "$a" -a 1 -eq $(echo "$a" | grep -m 1 -c "\.\(jpg\|png\)$")
  then
    prepend_image_size "$a"
  fi
done