#!/bin/bash -x ###################### #### "tractor-beam" is a compositing effect using imagemagick on a #### sequence of images. Uses the imagemagick option distort #### perspective on an image and then composites it over another. Also #### makes use of masks to create a wipe at the end. ###################### trap "rm -f folder-list caller *.mpc *.cache" 1 2 3 15 trap "exit 0" 2 # These are variables for "tractor-beam" which only have to be set # once every time "tractor-beam" is used. Defaults () { NEWBOTTOM=$BOTTOM # remembers original image height #X=this NEWMID=$(echo " scale=1; $MID - 0.5 " | bc ) # subtracts half-pixel from width: imagemagick half-pixel problem ! PERSP_CHANGE=$(echo "scale=3; ( ( $BOTTOM - 4 ) / 2 ) / $TRACTOR" | bc) # perspective distortion speed ! TOP=0 # remembers top end of image GRAY=$(echo " $MID * 0.1" | bc) # grayscale width for wipe ! WHITE=1 # Starting value for whiteout WHITE_SPEED=$(echo " scale=2; 3 / $FADE_TRACTOR" | bc) # white-out speed ! WIPE=0 # Starting value to chop the mask; creates wipe WIPE_SPEED=$(echo " scale=2; (( $WIDTH + $GRAY - ( $GRAY / 10 )) / 2 ) / $FADE_TRACTOR " | bc) # speed of wipe ! BARRELA=0 # start position of barrel distort BARRELD=1 # start position of barrel distort BARREL_CHANGE=$(echo " scale=3; 1 / $COMPOSE " | bc) # Amount the barrel distort should be changed per frame ENDBARRELA=$(echo "scale=3; $BARREL_CHANGE * $TRACTOR" | bc) # Not sure why this is here ENDBARRELD=$(echo "scale=3; 1 - ( $BARREL_CHANGE * $TRACTOR )" | bc) # Not sure why this is here ENDTOP=$(echo "scale=3; $PERSP_CHANGE * $TRACTOR" | bc) # Not sure why this is here ENDBOTTOM=$(echo "scale=3; $BOTTOM - $ENDTOP " | bc) # Not sure why this is here # Defaults are saved in a file, so that they can be exported as # variable in the parent process "master" echo -e "export NEWMID=$NEWMID \n export PERSP_CHANGE=$PERSP_CHANGE \n export WHITE_SPEED=$WHITE_SPEED \n export WIPE_SPEED=$WIPE_SPEED \n export BARREL_CHANGE=$BARREL_CHANGE ">defaults-tractor.list # Masks needed for the wipe at the end of the effect: A gradient and a # cookie cutter that gives the gradient the same shape as the image # who's perspective has been distorted. ! convert -size "$MID"x"$BOTTOM" xc:white \ \( -size "$BOTTOM"x"$GRAY" gradient:transparent-white -rotate 90 \) \ +append maskA.mpc # Writes various variables to file for first image in sequence needing that variable echo -e "WIPE=$WIPE\nWHITE=$WHITE \n TOP=$ENDTOP \n NEWBOTTOM=$ENDBOTTOM \n BARRELA=$ENDBARRELA \n BARRELD=$ENDBARRELD">vario-fade.list } # Change to the top and bottom of the right and left sides to create a # squeeze effect on the sides. Barrel distort curves the lines. The # file vario.list remembers the variables for when the process is # recalled for the next file. VarioPerspective () { TOP=$(echo "scale=2; $TOP + $PERSP_CHANGE " | bc) NEWBOTTOM=$(echo "scale=3; $NEWBOTTOM - $PERSP_CHANGE " | bc) BARRELA=$(echo " scale=3; $BARRELA + $BARREL_CHANGE " | bc ) BARRELD=$(echo " scale=3; $BARRELD - $BARREL_CHANGE " | bc ) echo -e "TOP=$TOP \n NEWBOTTOM=$NEWBOTTOM \n BARRELA=$BARRELA \n BARRELD=$BARRELD ">vario.list } # Set whiteout and wipe effects at the end of the composition. WIPE # and WHITE variables change file to file to create the # whiteout-wipe. The file vario-fade.list remembers the variables for # when the process is called for the next file. VarioFade () { LEFT_GRADIENT='-fx 'u*$WHITE' ( maskA.mpc -chop '$WIPE'x0 ) -compose dstin -composite' RIGHT_GRADIENT='-fx 'u*$WHITE' ( maskA.mpc -flop -gravity east -chop '$WIPE'x0 ) -compose dstin -composite' WIPE=$(echo "scale=3; $WIPE + $WIPE_SPEED" | bc) WHITE=$(echo "scale=3; $WHITE + $WHITE_SPEED" | bc) BARRELA=$(echo " scale=3; $BARRELA + $BARREL_CHANGE " | bc ) BARRELD=$(echo " scale=3; $BARRELD - $BARREL_CHANGE " | bc ) echo -e "WIPE=$WIPE\nWHITE=$WHITE\n BARRELA=$BARRELA \n BARRELD=$BARRELD \n TOP=$TOP \n NEWBOTTOM=$NEWBOTTOM">vario-fade.list } # Composition effect: squeezes together the top and bottom sides of # the right and left sides and then does a barndoor wipe which whites # out towards the sides Magick () { convert $2 \( $1 -crop 50%x100%+0+0 -alpha on -virtual-pixel transparent -distort perspective ' 0,0 0,'$TOP' 0,'$BOTTOM' 0,'$NEWBOTTOM' '$NEWMID','$BOTTOM' '$MID','$BOTTOM' '$NEWMID',0 '$MID',0 ' $LEFT_GRADIENT \( $1 -gravity east -crop 50%x100%+0+0 -alpha on -virtual-pixel transparent -distort perspective '0.5,0 0,0 0.5,'$BOTTOM' 0,'$BOTTOM' '$MID','$BOTTOM' '$MID','$NEWBOTTOM' '$MID',0 '$MID','$TOP'' $RIGHT_GRADIENT \) +append -distort barrel '0.0 0.0 0.0 1.0 '$BARRELA' 0.0 0.0 '$BARRELD'' \) -compose src-over -composite $3 } # Calls up infile and outfile names from caller.list file created by call-files script Caller () { INFILE1=`awk 'NR==1 {print $1}' caller.list` INFILE2=`awk 'NR==2 {print $1}' caller.list` OUTFILE=`awk 'NR==3' caller.list` } # Order of the composition. First runthrough makes sure default values # are saved, second does perspective change along with barrel distort, # third creates final mask for the fourth - the wipe-whiteout. if [ $COUNT = $DEFAULT_FETCH ]; then Caller Defaults Magick $INFILE1 $INFILE2 $OUTFILE VarioPerspective elif [ $COUNT -le $COMPOSE1 ]; then . vario.list Caller Magick $INFILE1 $INFILE2 $OUTFILE VarioPerspective else . vario-fade.list Caller VarioFade Magick $INFILE1 $INFILE2 $OUTFILE fi