Skip to content

Commit 667e894

Browse files
authored
Fixes (contribution by OWKenobi)
1 parent 1e9d296 commit 667e894

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

gear360pano.cmd

+32-24
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,40 @@ GOTO :CMDSCRIPT
1717
################################ Linux part here
1818

1919
# http://stackoverflow.com/questions/59895/can-a-bash-script-tell-which-directory-it-is-stored-in
20-
# Or dirname `dirname $0`
21-
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
22-
20+
DIR=$(dirname `which $0`)
2321
PTOTMPL="$DIR/gear360tmpl.pto"
2422
OUTTMPNAME="out"
2523
OUTNAME=$2
2624
JPGQUALITY=97
2725
PTOJPGFILENAME="dummy.jpg"
2826

2927
# Clean-up function
30-
function clean_up {
28+
clean_up() {
3129
if [ -d "$TEMPDIR" ]; then
32-
rm -rf "$TEMPDIR"
30+
rm -rf "$TEMPDIR"
3331
fi
3432
}
3533

3634
# Function to check if a command fails
3735
# http://stackoverflow.com/questions/5195607/checking-bash-exit-status-of-several-commands-efficiently
38-
function run_command {
36+
run_command() {
3937
"$@"
4038
local status=$?
4139
if [ $status -ne 0 ]; then
4240
echo "Error while running $1" >&2
41+
if [ $1 != "notify-send" ]; then
42+
# Display error in a nice graphical popup if available
43+
run_command notify-send "Error while running $1"
44+
fi
4345
clean_up
4446
exit 1
4547
fi
4648
return $status
4749
}
4850

49-
# Do stuff to make this thing run on various operating systems
51+
# Do stuff to make this thing run on various POSIX operating systems
5052
# http://stackoverflow.com/questions/3466166/how-to-check-if-running-in-cygwin-mac-or-linux
51-
function os_check {
53+
os_check() {
5254
case "$(uname -s)" in
5355

5456
Darwin)
@@ -80,7 +82,8 @@ fi
8082

8183
# Output name as second argument
8284
if [ -z "$2" ]; then
83-
OUTNAME=`basename "${1%.*}"`_pano.jpg
85+
#The output needs to be done in the folder of the original file if used via nautlius open-with
86+
OUTNAME=`dirname "$1"`/`basename "${1%.*}"`_pano.jpg
8487
fi
8588

8689
# OS check, custom settings for various OSes
@@ -91,34 +94,39 @@ os_check
9194
type nona >/dev/null 2>&1 || { echo >&2 "Hugin required but it's not installed. Aborting."; exit 1; }
9295

9396
# Create temporary directory locally to stay compatible with other OSes
94-
TEMPDIR=`mktemp -d -p .`
95-
STARTTS=`date +%s`
97+
# Not using '-p .' might cause some problems on non-unix systems (cygwin?)
98+
TEMPDIR=`mktemp -d`
9699

100+
STARTTS=`date +%s`
97101
# Stitch panorama (same file twice as input)
98102
echo "Processing input images (nona)"
99-
cmd="nona -o $TEMPDIR/$OUTTMPNAME \
100-
-m TIFF_m \
101-
-z LZW \
102-
$PTOTMPL \
103-
$1 \
104-
$1"
105-
run_command $cmd
103+
# We need to use run_command with many parameters, or $1 doesn't get
104+
# quoted correctly and we cannot use filenames with spaces
105+
run_command "nona" "-o" "$TEMPDIR/$OUTTMPNAME" \
106+
"-m" "TIFF_m" \
107+
"-z" "LZW" \
108+
$PTOTMPL \
109+
"$1" \
110+
"$1"
106111

107112
echo "Stitching input images (enblend)"
108-
cmd="enblend -o $OUTNAME \
109-
--compression=jpeg:$JPGQUALITY \
110-
$TEMPDIR/${OUTTMPNAME}0000.tif \
111-
$TEMPDIR/${OUTTMPNAME}0001.tif"
112-
run_command $cmd
113+
# We need to use run_command with many parameters,
114+
# or the directories don't get quoted correctly
115+
run_command "enblend" "-o" "$OUTNAME" \
116+
"--compression=jpeg:$JPGQUALITY" \
117+
"$TEMPDIR/${OUTTMPNAME}0000.tif" \
118+
"$TEMPDIR/${OUTTMPNAME}0001.tif"
113119

114-
# Remove temporary directory
120+
# Clean up any files/directories we created on the way
115121
clean_up
116122

117123
# Inform user about the result
118124
ENDTS=`date +%s`
119125
RUNTIME=$((ENDTS-STARTTS))
120126
echo Panorama written to $OUTNAME, took: $RUNTIME s
121127

128+
# Uncomment this if you don't do videos; otherwise, it is quite annoying
129+
#notify-send "Panorama written to $OUTNAME, took: $RUNTIME s"
122130
exit 0
123131

124132
################################ Windows part here

0 commit comments

Comments
 (0)