#!/bin/bash -x # Folders $1, $2 and $3 are required. A 3D box is created with images # from each of the folder on two sides of the box. Six copies of the # box are put in a 3x2 array. Each box is also rotated in a 360 degree # loop. COUNT=1 # Name of the first image to be created COUNT1=1 # Name of the first image in $1 to be called COUNT2=1 # Name of the first image in $2 to be called COUNT3=1 # Name of the first image in $3 to be called SKIPFILES=0 # Number of files skipped due to BUG, see below. # Total number of original files in each folder N1=$(ls $1 | wc -l) N2=$(ls $2 | wc -l) N3=$(ls $3 | wc -l) # Folder with the most images and how many highest_number=0 for x in $N1 $N2 $N3 do if [ $x -gt $highest_number ] ; then highest_number=$x fi done OTOTAL=$highest_number # Figure out what distance the angle will change from picture to # picture, with the folder with the most images acting as a guide. # Multiply by 3 so that the motion isn't too slow. ANG=` expr $OTOTAL / 360 \* 3` # Make sure that the angle of change is a divisor of 360. Set tiltvalue # so that right angles will be avoided as much as possible. if [ $ANG -lt 3 ]; then ANG=3 tiltvalue=-44 elif [ $ANG -gt 3 ] && [ $ANG -lt 6 ]; then ANG=6 tiltvalue=-45 elif [ $ANG -gt 6 ] && [ $ANG -lt 9 ]; then ANG=9 tiltvalue=-41 elif [ $ANG -gt 9 ] && [ $ANG -lt 12 ]; then ANG=12 tiltvalue=-46 elif [ $ANG -gt 12 ]; then ANG=15 tiltvalue=-40 fi # Finds number of files needed so that the rotation stops after a # complete rotation. ONETURN=` expr 360 / "$ANG" ` FILES=` expr $ONETURN \* \( $OTOTAL / $ONETURN \) ` ## While loop counting up to total number of files to be processed while [ $COUNT -le $FILES ]; do ## BUG: This has to be done because files over a certain size will ## cause error if the tilt is too close to a right angle. With this ## files up to 200x200 can be processed, whereby a small skip is ## apparent in the rotation. if [ $tiltvalue -ge -3 -o $tiltvalue -le -87 -a $tiltvalue -ge -93 \ -o $tiltvalue -le -177 -a $tiltvalue -ge -183 -o $tiltvalue -le \ -267 -a $tiltvalue -ge -273 -o $tiltvalue -le -357 ]; then ## Calculating whether another revolution can be done because of files ## skipped due to BUG let FILES=FILES-1 let SKIPFILES=SKIPFILES+1 if [ $SKIPFILES -eq $ONETURN ]; then let FILES=FILES+$ONETURN let SKIPFILES=0 fi ## If the tiltvalue isn't close to a right angle, we can go ahead and process else VAR=`printf "%03d" $COUNT` ## If the files in a folder are used up before those in the other ## folders, then we loop back and process the first files in the ## respective folder. Here we give the names of the files to call: 001, 002, etc... if [ $COUNT1 -le $N1 ]; then VAR1=$(printf "%03d" $COUNT1) else VAR1=$(printf "%03d" 1) COUNT1=1 fi if [ $COUNT2 -le $N2 ]; then VAR2=$(printf "%03d" $COUNT2) else VAR2=$(printf "%03d" 1) COUNT2=1 fi if [ $COUNT3 -le $N3 ]; then VAR3=$(printf "%03d" $COUNT3) else VAR3=$(printf "%03d" 1) COUNT3=1 fi ## The script 3Dbox is from Fred Weinhaus, ## http://www.fmwconcepts.com/imagemagick/index.html ## 3 images at a time are made to a box. The tilt value changes during ## the course of the program. 3Dbox pan=45 tilt=$tiltvalue pef=0.6 filter=lanczos format=center \ mode=mirror bgcolor=transparent $1/$VAR1.png $2/$VAR2.png $3/$VAR3.png box_1.miff ## Box is copied 6 times on an image to create a 3x2 array. convert \( box_1.miff box_1.miff box_1.miff +append \) \( box_1.miff box_1.miff box_1.miff +append \) \ -append $VAR.jpg ## The names for the next files to be called up or processed let COUNT=COUNT+1 let COUNT1=COUNT1+1 let COUNT2=COUNT2+1 let COUNT3=COUNT3+1 fi ## Add $tiltvalue to the current angle of tilt. tiltvalue=`expr $tiltvalue - $ANG ` ## If the angle is less than -360 degrees, return the angle to 0 degrees if [ $tiltvalue -lt -360 ]; then tiltvalue=`expr $tiltvalue + 360` fi done