#! /bin/bash # ===== some constants WIDTH=240 HEIGHT=240 OVERLAPWIDTH=0 OVERLAPHEIGHT=0 SCREENHEIGHT=265 SCREENWIDTH=240 QUALITY=50 # ===== the filenames INFILE=$1 EXTENSION=${INFILE/#*.} OUTFILE=${1/.$EXTENSION} # ===== check the syntax if [[ "$1" == "" ]]; then echo "USAGE: maptozaurus IMAGEFILE [image type]" echo " image type optional, for example gif,png,jpg" echo " for more image types do a \"man convert\"" exit 1 fi # ==== is there a file-conflict if [ -d ./home ]; then echo "There's already a ./home folder. Please remove that first!" exit 1 fi if [ -e ./control ]; then echo "There's already a control file. Remove it first!" exit 1 fi if [ -e ./control.tar.gz ]; then echo "There's already a control.tar.gz file. Remove it first!" exit 1 fi if [ -e ./data.tar.gz ]; then echo "There's already a data.tar.gz file. Remove it first!" exit 1 fi # ===== Is ImageMagick installed? if [[ "`which identify`" == "" ]]; then echo Cannot find the program \"identify\"! Is \"ImageMagick\" installed? exit 2; fi # ===== image type for the maps echo Extracting picture information... IDENTIFY_STR=`identify -format "%m %w %h" $INFILE` if [[ "$2" != "" ]]; then EXTENSION="$2" else EXTENSION=`echo "$IDENTIFY_STR" | cut -d" " -f1` fi # ===== make it lowercase EXTENSION=`echo "$EXTENSION" | tr [A-Z] [a-z]` if [[ "$EXTENSION" == "jpeg" ]]; then EXTENSION=jpg fi # ===== no converter specified? if [[ "`which convert`" == "" ]]; then echo Cannot find the program \"convert\"! exit 2 fi if [[ "$EXTENSION" == "" ]]; then echo Cannot identify the image-type or cannot find the file! exit 2 fi if [ -d ./${OUTFILE} ]; then echo "There's already an image folder ${OUTFILE}." exit 2 fi mkdir "$OUTFILE" cd "$OUTFILE" INFILE="../$INFILE" # ===== get the image size MAXWIDTH=`echo $IDENTIFY_STR | cut -d" " -f2` MAXHEIGHT=`echo $IDENTIFY_STR | cut -d" " -f3` echo Recognized size: $MAXWIDTH/$MAXHEIGHT # ===== set some variables X=0 Y=0 XMAX=$[$MAXWIDTH/$WIDTH+1] if [[ $[$XMAX*$[$WIDTH-$OVERLAPWIDTH]] == $[$MAXWIDTH+$WIDTH] ]]; then XMAX=$[$XMAX-1] fi YMAX=$[$MAXHEIGHT/$HEIGHT+1] if [[ $[$YMAX*$[$HEIGHT-$OVERLAPHEIGHT]] == $[$MAXHEIGHT+$HEIGHT] ]]; then YMAX=$[$YMAX-1] fi echo Splitting from 0/0 to $[XMAX-1]/$[YMAX-1] # ===== cutting image into pieces convert -crop "$WIDTH"x"$HEIGHT" -quality $QUALITY "$INFILE" "$OUTFILE"_"%d"."$EXTENSION" # ===== renaming files while [[ $Y != $YMAX ]]; do while [[ $X != $XMAX ]]; do echo Processing $X/$Y if [[ "$EXTENSION" == "gif" ]]; then # ppmtogif generates better gif files! cat "$OUTFILE"_$[$Y*$XMAX+$X]."$EXTENSION" | giftopnm | ppmtogif > "$OUTFILE"_"$X"_"$Y"."$EXTENSION" rm "$OUTFILE"_$[$Y*$XMAX+$X]."$EXTENSION" else mv "$OUTFILE"_$[$Y*$XMAX+$X]."$EXTENSION" "$OUTFILE"_"$X"_"$Y"."$EXTENSION" fi # ===== next column X=$[$X+1] done # ===== next row X=0 Y=$[$Y+1] done # ===== adding overview if [[ "$EXTENSION" == "gif" ]]; then convert -geometry "$SCREENWIDTH"x"$SCREENHEIGHT" "$INFILE" -colors 31 temp.gif cat temp.gif | giftopnm | ppmtogif > "$OUTFILE"_ov."$EXTENSION" rm temp.gif else convert -geometry "$SCREENWIDTH"x"$SCREENHEIGHT" "$INFILE" "$OUTFILE"_ov."$EXTENSION" fi # ===== leaving image-folder cd .. # ===== creating folders for ipkg echo Creating the right folders mkdir ./home mkdir ./home/QtPalmtop mkdir ./home/QtPalmtop/share mkdir ./home/QtPalmtop/share/jmap # ===== moving the image-files into the right folder mv ${OUTFILE} ./home/QtPalmtop/share/jmap/ # ===== make a nice ipkg DATE=$(date +"%Y%m%d") FILE=./jmap-${OUTFILE}_${DATE}_arm.ipk # ===== package-information echo -ne "Package: jmap-${OUTFILE} InstalledSize: $(du -sh ./home | cut -f1) Filename: ${FILE} Maintainer: $(whoami) Architecture: arm Version: ${DATE} Description: JMap ${OUTFILE} " > ./control # ===== creating tar -czf data.tar.gz ./home tar -czf control.tar.gz ./control tar -czf ${FILE} ./data.tar.gz ./control.tar.gz # ===== removing temp-files rm ./data.tar.gz ./control.tar.gz ./control # ===== removing the NEW folders and NEW created images rm -rf ./home