@@ -17,38 +17,40 @@ GOTO :CMDSCRIPT
17
17
################################ Linux part here
18
18
19
19
# 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`)
23
21
PTOTMPL=" $DIR/gear360tmpl.pto"
24
22
OUTTMPNAME=" out"
25
23
OUTNAME=$2
26
24
JPGQUALITY=97
27
25
PTOJPGFILENAME=" dummy.jpg"
28
26
29
27
# Clean-up function
30
- function clean_up {
28
+ clean_up() {
31
29
if [ -d " $TEMPDIR" ]; then
32
- rm -rf " $TEMPDIR"
30
+ rm -rf " $TEMPDIR"
33
31
fi
34
32
}
35
33
36
34
# Function to check if a command fails
37
35
# http://stackoverflow.com/questions/5195607/checking-bash-exit-status-of-several-commands-efficiently
38
- function run_command {
36
+ run_command() {
39
37
" $@"
40
38
local status=$?
41
39
if [ $status -ne 0 ]; then
42
40
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
43
45
clean_up
44
46
exit 1
45
47
fi
46
48
return $status
47
49
}
48
50
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
50
52
# http://stackoverflow.com/questions/3466166/how-to-check-if-running-in-cygwin-mac-or-linux
51
- function os_check {
53
+ os_check() {
52
54
case " $(uname -s)" in
53
55
54
56
Darwin)
80
82
81
83
# Output name as second argument
82
84
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
84
87
fi
85
88
86
89
# OS check, custom settings for various OSes
@@ -91,34 +94,39 @@ os_check
91
94
type nona > /dev/null 2 >& 1 || { echo >& 2 " Hugin required but it's not installed. Aborting." ; exit 1; }
92
95
93
96
# 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 `
96
99
100
+ STARTTS=`date +%s`
97
101
# Stitch panorama (same file twice as input)
98
102
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"
106
111
107
112
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"
113
119
114
- # Remove temporary directory
120
+ # Clean up any files/directories we created on the way
115
121
clean_up
116
122
117
123
# Inform user about the result
118
124
ENDTS=`date +%s`
119
125
RUNTIME=$((ENDTS-STARTTS))
120
126
echo Panorama written to $OUTNAME, took: $RUNTIME s
121
127
128
+ # Uncomment this if you don't do videos; otherwise, it is quite annoying
129
+ #notify-send " Panorama written to $OUTNAME, took: $RUNTIME s"
122
130
exit 0
123
131
124
132
################################ Windows part here
0 commit comments