#!/bin/sh
#
# program to scale all xpm-files of a directory into a new directory
# the icons are recreated (using 'create_icons')
# uses netpbm
#
# 15. Januar 2002
# Diether Knof <dknof@gmx.de>


if [ ! $1 ]; then
  echo "Please give the scaling factor"
  exit 1
fi
if [ ! $2 ]; then
  echo "please give the name of the new directory"
  exit 1
fi

rm -rf $2
cp -a 90x140 $2
cd $2
chmod +w . -R

for f in `find . -name "*.xpm"`; do
  echo $f
  xpmtoppm --alphaout=- $f \
    | pnmscale $1 2>/dev/null \
    > $f.mask.pbm
  xpmtoppm $f \
    | pnmscale $1 \
    | ppmtoxpm -alphamask=$f.mask.pbm 2>/dev/null\
    > $f.tmp
  mv $f.tmp $f
  rm -f $f.mask.pbm
done

for d in `find . -name "icons"`; do
  if [ -d $d ]; then
    pushd . >/dev/null
      cd $d/
      create_icons
    popd >/dev/null
  fi
done