#!/bin/bash
# Copyright: David D Lowe (c) 2009
# released under the GPL v2


# command line parameters
ifile=$1
ofile=$2

rm -rf /tmp/pigment-thumbnailer
mkdir -p /tmp/pigment-thumbnailer
cd /tmp/pigment-thumbnailer
tar -xzf "$ifile" --wildcards --get information/*.jpg
cd -
ls -1 /tmp/pigment-thumbnailer/information/*.jpg > /dev/null 2>&1
if [ "$?" == "0" ]; then
  mv /tmp/pigment-thumbnailer/information/*.jpg "$ofile"
else
  cd /tmp/pigment-thumbnailer
  tar -xzf "$ifile" --wildcards --get information/*.png
  cd -
  ls -1 /tmp/pigment-thumbnailer/information/*.png > /dev/null 2>&1
  if [ "$?" == "0" ]; then
    mv /tmp/pigment-thumbnailer/information/*.png "$ofile"
  fi
fi
rm -rf /tmp/pigment-thumbnailer


if [ -x /usr/bin/composite ]; then
    convert -scale 100x75 "$ofile" "$ofile"
    composite -gravity SouthEast /usr/share/epidermis/data/transparent-logo.png "$ofile" "$ofile"
fi

