* Use the bounding box properly
authorBrett Parker <iDunno@sommitrealweird.co.uk>
Tue, 1 Jan 2008 18:10:21 +0000 (18:10 +0000)
committerBrett Parker <iDunno@sommitrealweird.co.uk>
Tue, 1 Jan 2008 18:10:21 +0000 (18:10 +0000)
* Shift large chunk of image size checks in to own function

bpgallery.sh

index 94bd4eb2ee1b87ac4f8450e0d497f151f7cd51f1..3191eed9db26a7a89f810c00d652aaff0f8e3136 100755 (executable)
@@ -80,8 +80,9 @@ div.thumbnail {
        float: left;
        padding: 20px;
        border: 0px;
-       width: ${WIDTH}px;
+       width: ${MAXWIDTH}px;
        height: ${MAXHEIGHT}px;
+       text-align: center;
 }
 
 div.caption {
@@ -530,11 +531,57 @@ Version: $VERSION
 END
 }
 
+function check_dimensions() {
+       wantedwidth=$1
+       wantedheight=$2
+       dir=$3
+       filename=$4
+       iconwidth=$($IDENTIFYCOMMAND -format "%wx%h" "$dir/$filename")
+       iconheight=${iconwidth//*x}
+       iconwidth=${iconwidth//x*}
+       # are the dimensions correctish?
+       imagesizeright=1
+       if [ ! -z $wantedheight ]; then
+               if [ $wantedwidth -ne $iconwidth ] && [ $wantedheight -ne $iconheight ]; then
+                       imagesizeright=0
+               else
+                       # make sure that both of the dimensions are smaller than they
+                       # should be
+                       if [ $iconwidth -gt $wantedwidth ] || [ $iconheight -gt $wantedheight ]; then
+                               imagesizeright=0
+                       fi
+               fi
+       else
+               if [ $wantedwidth -ne $iconwidth ]; then
+                       imagesizeright=0
+               fi
+       fi
+       echo $imagesizeright
+}
+
 function generate_resized_images() {
        $ECHOCOMMAND "Generating $2"
+       width=$1
+       height=${width//*x}
+       if [ $width != $height ]; then
+               width=${width//x*}
+       else
+               height=""
+       fi
        currentimage=0
        totalimages=$($FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 -I {} $ECHOCOMMAND {} | $WCCOMMAND);
-       imagestoupdate=$($FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 -I {} $ECHOCOMMAND {} | while read filename; do filename=${filename//\"/\\\"}; if [ ! -r "$2/$filename" ] || [ "$filename" -nt "$2/$filename" ] || [ $($IDENTIFYCOMMAND -format "%w" "$2/$filename") -ne $1 ]; then $ECHOCOMMAND $filename; fi; done | $WCCOMMAND)
+       imagestoupdate=$($FINDCOMMAND . $FINDIMAGESOPTIONS |
+               $XARGSCOMMAND -0 -I {} $ECHOCOMMAND {} |
+               while read filename; do
+                       filename=${filename//\"/\\\"}
+                       imagesizeright=$(check_dimensions "$width" "$height" "$2" "$filename")
+                       if [ ! -r "$2/$filename" ] ||
+                               [ "$filename" -nt "$2/$filename" ] ||
+                               [ $imagesizeright -ne 1 ]; then
+                               $ECHOCOMMAND $filename
+                       fi
+               done |
+               $WCCOMMAND)
        
        if [ $totalimages -eq 0 ]; then
                # might as well exit at this point - there are no pictures
@@ -561,13 +608,29 @@ function generate_resized_images() {
                $ECHOCOMMAND "Generating $imagestoupdate of $totalimages $2"
        fi
        
-       $FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 -I {} $ECHOCOMMAND {} | while read filename; do tempfilename=${filename//\"/\\\"/}; if [ ! -r "$2/$tempfilename" ] || [ "$tempfilename" -nt "$2/$tempfilename" ] || [ $($IDENTIFYCOMMAND -format "%w" "$2/$filename") -ne $1 ]; then $ECHOCOMMAND -n $filename; $ECHOCOMMAND -n -e "\000"; fi; done | $XARGSCOMMAND -0 --verbose --max-procs=4 -I {} $CONVERTTOOL -resize $1 '{}' $2/'{}' 2>&1 | while read throwout; do $ECHOCOMMAND done: $currentimage/$imagestoupdate images; currentimage=$((currentimage+1)); done
+       $FINDCOMMAND . $FINDIMAGESOPTIONS | \
+               $XARGSCOMMAND -0 -I {} $ECHOCOMMAND {} | \
+               while read filename; do 
+                       tempfilename=${filename//\"/\\\"/}; 
+                       imagesizeright=$(check_dimensions "$width" "$height" "$2" "$filename")
+                       if [ ! -r "$2/$tempfilename" ] \
+                               || [ "$tempfilename" -nt "$2/$tempfilename" ] \
+                               || [ $imagesizeright -ne 1 ]; then 
+                                       $ECHOCOMMAND -n $filename
+                                       $ECHOCOMMAND -n -e "\000"
+                       fi
+               done | \
+               $XARGSCOMMAND -0 --verbose --max-procs=4 -I {} $CONVERTTOOL -resize $1 '{}' $2/'{}' 2>&1 | \
+                       while read throwout; do
+                               $ECHOCOMMAND done: $currentimage/$imagestoupdate images
+                               currentimage=$((currentimage+1))
+                       done
        $ECHOCOMMAND done: $imagestoupdate/$imagestoupdate images
        $ECHOCOMMAND "Completed generating $2 for $totalimages images"
 }
 
 function generate_thumbs() {
-       if [[ ! -z $HEIGHT ]]; then
+       if [ ! -z $HEIGHT ]; then
                generate_resized_images "${WIDTH}x${HEIGHT}" $ICONSDIRECTORY
        else
        generate_resized_images $WIDTH $ICONSDIRECTORY
@@ -575,8 +638,8 @@ function generate_thumbs() {
 }
 
 function generate_medium() {
-       if [[ ! -z $MEDIUMHEIGHT ]]; then
-               generate_resized_images "${WIDTH}x${HEIGHT}" $MEDIUMDIRECTORY
+       if [ ! -z $MEDIUMHEIGHT ]; then
+               generate_resized_images "${MEDIUMWIDTH}x${MEDIUMHEIGHT}" $MEDIUMDIRECTORY
        else
                generate_resized_images $MEDIUMWIDTH $MEDIUMDIRECTORY
        fi