#!/bin/sh # cpt=0 #Create a destination dir called pgmDir pgmDir=/media/castor/ICAR AZ/raw boss/PGMs tmpcfg=`mktemp ` echo " 1 ppg Camera WB no Color matrix sRGB System default " > $tmpcfg for i in *.* ; do # for DNG images echo "Image $cpt ($i)" #Raw Conversion ufraw-batch --conf=$tmpcfg $i --output=/tmp/${i%.*}.ppm #Convertion into PMG and auto orientation to have an oriented image convert -auto-orient /tmp/${i%.*}.ppm /tmp/${i%.*}.pgm line=`identify /tmp/${i%.*}.pgm` # echo "$line" arg1=`echo $line | cut -d " " -f3-3 | cut -d " " -f2-2` #f4-4 and f3-3 if path have a space length=`echo $arg1 | cut -d "x" -f1-1` height=`echo $arg1 | cut -d "x" -f2-2` #echo "$arg1" #echo "$length" #echo "$height" if [ "$height" -lt "$length" ] ; then maxSize=`echo $length` newLength=`echo $length*512/$height | bc` newHeight=512 newShiftLength=`echo $newLength/2-512/2 |bc` newShiftHeight=0 convert -resize x`echo $newHeight` /tmp/${i%.*}.pgm /tmp/${i%.*}.R.pgm else maxSize=`echo $height` newLength=512 newHeight=`echo $height*512/$length | bc` newShiftLength=0 newShiftHeight=`echo $newHeight/2-512/2 |bc` convert -resize `echo $newLength`x /tmp/${i%.*}.pgm /tmp/${i%.*}.R.pgm fi if [ "$newLength" -lt 512 ] ; then newLength=512 fi if [ "$newHeight" -lt 512 ] ; then newHeight=512 fi #echo "$maxSize" echo "$newLength" echo "$newHeight" echo "$newShiftLength" echo "$newShiftHeight" #convert -depth 1 -crop 512x512+`echo $newShiftLength`+`echo $newShiftHeight` $i.R.pgm `echo $pgmDir/$cpt.pgm` convert -crop 512x512+`echo $newShiftLength`+`echo $newShiftHeight` /tmp/${i%.*}.R.pgm $pgmDir/${i%.*}.pgm #rm /tmp/${i%.*}.pgm rm /tmp/${i%.*}.ppm #rm /tmp/${i%.*}.R.pgm cpt=`echo $cpt+1 |bc` done rm $tmpcfg -f