#!/bin/sh

set -e

if [ -z "$1" ]
then
  echo "usage: $0 IMAGE_FILE [SIZE [SUFFIX]]"
  exit 1
fi

FILE=$1
SIZE=${2:-256x256}
SUFFIX=$3

# make sure SUFFIX starts with a '-'
case "$SUFFIX" in
  -*) ;;
  "") ;;
  *) SUFFIX=-$SUFFIX ;;
esac

NAME=$(basename "$FILE")
NAME=${NAME%.*}  # remove extension
NAME=${NAME%-*}  # remove size info from pixabay images

convert "$FILE" -resize "$SIZE" "$NAME$SUFFIX.ppm"
echo "fichier $NAME$SUFFIX.ppm créé"

convert "$NAME$SUFFIX.ppm" -set colorspace Gray "$NAME$SUFFIX-seeds.ppm"
echo "fichier $NAME$SUFFIX-seeds.ppm créé"
