#!/bin/bash # Author: Fernando Luiz Prochnow Ramme, June/30/2015 # Perspective slice plot - vertical perspective to left, version 1.0.0 # INPUT: two or three or four images (PNG format) in the same view scale (width,height) in pixels # OUTPUT: the combined image in perspective view. # Developer: Fernando Luiz Prochnow Ramme # ----------------------------------------------------------------------------------------------------------------------------- # define usage function function usage { echo "USAGE: pv-vl.sh OUTFILE INFILE1 INFILE2 [INFILE3] [INFILE4]" echo " OUTFILE: path/filename.extension of output image" echo " INFILE1: path/filename.extension of first input image" echo " INFILE2: path/filename.extension of second input image" echo " INFILE3: optional, path/filename.extension of third input image" echo " INFILE4: optional, path/filename.extension of fourth input image" } # # ----------------------------------------------------------------------------------------------------------------------------- # function to report error messages, usage and exit function errMsg { echo "" echo $1 echo "" usage exit 1 } # # ----------------------------------------------------------------------------------------------------------------------------- # Apply Perspective View function processTwoInputs { echo "Starting..." # TEMP="/tmp" OUTFILE=$1 OUTFILEF="${OUTFILE%%.*}" OUTFILEFN="${OUTFILEF##*/}" INFILE1=$2 INFILE2=$3 # # get Filename without extensions INFILE1F="${INFILE1%%.*}" INFILE2F="${INFILE2%%.*}" # # Remove all the prefix until the "/" character INFILE1FN="${INFILE1F##*/}" INFILE2FN="${INFILE2F##*/}" # # get Full extensions INFILE1E="${INFILE1#*.}" INFILE2E="${INFILE2#*.}" # #saves the absolute path of the current working directory to the variable cwd cwd="`dirname ${BASH_SOURCE[0]}`" #echo "$cwd" # # Apply Perspective View - vertical perspective to left OUTFILE1TMP=$INFILE1FN"_out."$INFILE1E OUTFILE2TMP=$INFILE2FN"_out."$INFILE2E $cwd/perspective.sh 125,0,0 $INFILE1 $OUTFILE1TMP # only processing second file if different from first filename if [ $OUTFILE1TMP != $OUTFILE2TMP ] then $cwd/perspective.sh 125,0,0 $INFILE2 $OUTFILE2TMP fi # # Combine images and generate OUTPUT image convert \( $OUTFILE1TMP -set colorspace sRGB $cwd/gray240.png $OUTFILE2TMP $cwd/gray240.png -gravity center -background 'rgb(240,240,240)' +append \) \ -background white -gravity center -set colorspace sRGB -append $OUTFILE # # Convert OUTPUT image to PDF #convert -quality 100 -compress Zip $OUTFILE $OUTFILE.pdf #remove fist temporary file rm $OUTFILE1TMP # only remove second temporary file if created in the processing if [ $OUTFILE1TMP != $OUTFILE2TMP ] then rm $OUTFILE2TMP fi } # # ----------------------------------------------------------------------------------------------------------------------------- # Apply Perspective View function processThreeInputs { echo "Starting..." # TEMP="/tmp" OUTFILE=$1 OUTFILEF="${OUTFILE%%.*}" OUTFILEFN="${OUTFILEF##*/}" INFILE1=$2 INFILE2=$3 INFILE3=$4 # # get Filename without extensions INFILE1F="${INFILE1%%.*}" INFILE2F="${INFILE2%%.*}" INFILE3F="${INFILE3%%.*}" # # Remove all the prefix until the "/" character INFILE1FN="${INFILE1F##*/}" INFILE2FN="${INFILE2F##*/}" INFILE3FN="${INFILE3F##*/}" # # get Full extensions INFILE1E="${INFILE1#*.}" INFILE2E="${INFILE2#*.}" INFILE3E="${INFILE3#*.}" # #saves the absolute path of the current working directory to the variable cwd cwd="`dirname ${BASH_SOURCE[0]}`" #echo "$cwd" # # Apply Perspective View - vertical perspective to left OUTFILE1TMP=$INFILE1FN"_out."$INFILE1E OUTFILE2TMP=$INFILE2FN"_out."$INFILE2E OUTFILE3TMP=$INFILE3FN"_out."$INFILE3E $cwd/perspective.sh 125,0,0 $INFILE1 $OUTFILE1TMP # only processing second file if different from first filename if [ $OUTFILE2TMP != $OUTFILE1TMP ] then $cwd/perspective.sh 125,0,0 $INFILE2 $OUTFILE2TMP fi # only processing third file if different from first filename if [ $OUTFILE3TMP != $OUTFILE1TMP ] then $cwd/perspective.sh 125,0,0 $INFILE3 $OUTFILE3TMP fi # # Combine images and generate OUTPUT image convert \( $OUTFILE1TMP -set colorspace sRGB $cwd/gray240.png $OUTFILE2TMP $cwd/gray240.png $OUTFILE3TMP $cwd/gray240.png -gravity center -background 'rgb(240,240,240)' +append \) \ -background white -gravity center -set colorspace sRGB -append $OUTFILE # # Convert OUTPUT image to PDF #convert -quality 100 -compress Zip $OUTFILE $OUTFILE.pdf # # CLEAN temporary files #remove fist temporary file rm $OUTFILE1TMP # only remove second temporary file if created in the processing if [ $OUTFILE2TMP != $OUTFILE1TMP ] then rm $OUTFILE2TMP fi # only remove third temporary file if created in the processing if [ $OUTFILE3TMP != $OUTFILE1TMP ] then rm $OUTFILE3TMP fi } # # ----------------------------------------------------------------------------------------------------------------------------- # Apply Perspective View function processFourInputs { echo "Starting..." # TEMP="/tmp" OUTFILE=$1 OUTFILEF="${OUTFILE%%.*}" OUTFILEFN="${OUTFILEF##*/}" INFILE1=$2 INFILE2=$3 INFILE3=$4 INFILE4=$5 # # get Filename without extensions INFILE1F="${INFILE1%%.*}" INFILE2F="${INFILE2%%.*}" INFILE3F="${INFILE3%%.*}" INFILE4F="${INFILE4%%.*}" # # Remove all the prefix until the "/" character INFILE1FN="${INFILE1F##*/}" INFILE2FN="${INFILE2F##*/}" INFILE3FN="${INFILE3F##*/}" INFILE4FN="${INFILE4F##*/}" # # get Full extensions INFILE1E="${INFILE1#*.}" INFILE2E="${INFILE2#*.}" INFILE3E="${INFILE3#*.}" INFILE4E="${INFILE4#*.}" # #saves the absolute path of the current working directory to the variable cwd cwd="`dirname ${BASH_SOURCE[0]}`" #echo "$cwd" # # Apply Perspective View - vertical perspective to left OUTFILE1TMP=$INFILE1FN"_out."$INFILE1E OUTFILE2TMP=$INFILE2FN"_out."$INFILE2E OUTFILE3TMP=$INFILE3FN"_out."$INFILE3E OUTFILE4TMP=$INFILE4FN"_out."$INFILE4E $cwd/perspective.sh 125,0,0 $INFILE1 $OUTFILE1TMP # only processing second file if different from first filename if [ $OUTFILE2TMP != $OUTFILE1TMP ] then $cwd/perspective.sh 125,0,0 $INFILE2 $OUTFILE2TMP fi # only processing third file if different from first filename if [ $OUTFILE3TMP != $OUTFILE1TMP ] then $cwd/perspective.sh 125,0,0 $INFILE3 $OUTFILE3TMP fi # only processing fourth file if different from first filename if [ $OUTFILE4TMP != $OUTFILE1TMP ] then $cwd/perspective.sh 125,0,0 $INFILE4 $OUTFILE4TMP fi # # Combine images and generate OUTPUT image convert \( $OUTFILE1TMP -set colorspace sRGB $cwd/gray240.png $OUTFILE2TMP $cwd/gray240.png $OUTFILE3TMP $cwd/gray240.png $OUTFILE4TMP $cwd/gray240.png -gravity center -background 'rgb(240,240,240)' +append \) \ -background white -gravity center -set colorspace sRGB -append $OUTFILE # # Convert OUTPUT image to PDF #convert -quality 100 -compress Zip $OUTFILE $OUTFILE.pdf # # CLEAN temporary files #remove fist temporary file rm $OUTFILE1TMP # only remove second temporary file if created in the processing if [ $OUTFILE2TMP != $OUTFILE1TMP ] then rm $OUTFILE2TMP fi # only remove third temporary file if created in the processing if [ $OUTFILE3TMP != $OUTFILE1TMP ] then rm $OUTFILE3TMP fi # only remove fourth temporary file if created in the processing if [ $OUTFILE4TMP != $OUTFILE1TMP ] then rm $OUTFILE4TMP fi } # # ----------------------------------------------------------------------------------------------------------------------------- # INITIALIZATION # # test for correct number of arguments and get values if [ $# -eq 0 ] then # help information usage exit 0 elif [ $# -lt 3 ] then errMsg "--- NO PARAMETER VALUES WERE PROVIDED ---" elif [ $# -eq 3 ] then echo "processing INPUT1 and INPUT2" processTwoInputs $1 $2 $3 elif [ $# -eq 4 ] then echo "processing INPUT1 INPUT2 INPUT3" processThreeInputs $1 $2 $3 $4 elif [ $# -eq 5 ] then echo "processing INPUT1 INPUT2 INPUT 3 INPUT4" processFourInputs $1 $2 $3 $4 $5 elif [ $# -gt 5 ] then usage exit 0 fi # -----------------------------------------------------------------------------------------------------------------------------