File: qiv-command.example

package info (click to toggle)
qiv 3.0.2-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 512 kB
  • sloc: ansic: 4,897; makefile: 109; sh: 100; python: 45
file content (162 lines) | stat: -rwxr-xr-x 5,406 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash

###
### QUICK IMAGE VIEWER "qiv-command" file
### http://qiv.spiegl.de/
###
### This file will be launched by QIV if you push 0-9 (or any other free key)
### NEW:  Now you can use all free keys for qiv-command.
### NEW:  If you press "X" followed by any string,
###       qiv-command is called with X and this string
###
### Just put it in a directory that is in your path
###
### Note:
###  If the first line of the output is like "NEWNAME=xxxxxxx" then qiv
###  thinks that the filename of the currently displayed image has
###  changed to this new name and updates its internal filelist.
###  This is very useful when using qiv-command to rename files.

#
# some examples by Andy Spiegl <qiv.andy@spiegl.de>
# Created:     2002-05-12
# Last change: 2021-12-14
#
# more examples (renaming, jpg comments) by Clint Pachl <pachl@ecentryx.com>
#
# needs jhead to rotate JPEG without loss of Exif Jpeg headers
# jhead is:
# Program for extracting Digicam setting information from Exif Jpeg headers
# used by most Digital Cameras.  v2.6 by Matthias Wandel, Dec 26 2006
# http://www.sentex.net/~mwandel/jhead  mwandel@sentex.net

# Syntax: qiv-command [pressed_key] [image_filename_with_full_path]
pressed_key=$1  	# key(s) pressed in qiv
filename=$2         # image filename with full path

echo "You pressed the $pressed_key key while watching $filename"

case "$pressed_key" in

  0)
    # do something with the image ($2) ->
    #
    # example: copy
    # cp "$2" "/home/myfiles/download/";
    #
    # example: move
    # mv "$2" "/home/myfiles/download/";
    # echo "NEWNAME=/home/myfiles/download/$2";
    #
    # example: show EXIF Header using "exiftool" or "jhead"
    # exiftool "$filename"
    # jhead "$filename"
    # more sophisticated for better infos (adjust paths!)
#    if [ -r $HOME/local/var/exiftool.tags.for.qiv-command ]; then
#      exiftool `xargs < $HOME/local/var/exiftool.tags.for.qiv-command` "$filename" \
#       | grep -v -f $HOME/local/var/exiftool.grep-exclude-pattern.for.qiv-command
#      jhead -nofinfo "$filename" | grep -i -E '^(JPEG Quality |Caption )'
#    else
#      jhead -nofinfo "$filename"
#    fi

    echo -ne "0 was pushed.\nStart your own programs by editing the\n\"$0\" file!";
    ;;


  1|2|3|4)
    echo -ne "$pressed_key was pushed.\nStart your own programs by editing the\n\"$0\" file!";
    ;;

  5)
    # Open picture for editing with gimp. Send stdout/stderr to /dev/null, otherwise qiv will wait for gimp to end.
    gimp "$filename" > /dev/null 2>&1 &
    ;;

  6)
    # Modify comment header. Fire up an xterm running EDITOR to edit comment.
    #xterm -e jhead -ce "$filename"
    jhead -ce "$filename"
    ;;

  7)
    # Open picture for editing with gimp. Send stdout/stderr to /dev/null, otherwise qiv will wait for gimp to end.
    gimp "$filename" > /dev/null 2>&1 &
    ;;

  8) # lossless rotation of JPG, without losing EXIF tags
    echo 2>&1 "Rotating to the left."
    jhead -cmd "jpegtran -perfect -rotate 270 -outfile &o &i" "$filename" >/dev/null
    # set timestamp of file to Date/Time when the photo was taken
    jhead -q -ft "$filename" >/dev/null
    ;;

  9) # lossless rotation of JPG, without losing EXIF tags
    echo 2>&1 "Rotating to the right."
    jhead -cmd "jpegtran -perfect -rotate 90 -outfile &o &i" "$filename" >/dev/null
    # set timestamp of file to Date/Time when the photo was taken
    jhead -q -ft "$filename" >/dev/null
    ;;

  # with "^"-prefix: forced (i.e. possibly NOT lossless) rotation
  ^8) # rotate JPG, but possibly losing quality
    echo 2>&1 "Forcing rotation to the left."
    jhead -cmd "jpegtran -rotate 270 -outfile &o &i" "$filename" >/dev/null
    # set timestamp of file to Date/Time when the photo was taken
    jhead -q -ft "$filename" >/dev/null
    ;;

  ^9) # rotate JPG, but possibly losing quality
    echo 2>&1 "Forcing rotation to the right."
    jhead -cmd "jpegtran -rotate 90 -outfile &o &i" "$filename" >/dev/null
    # set timestamp of file to Date/Time when the photo was taken
    jhead -q -ft "$filename" >/dev/null
    ;;

  ^g) # call gps2url to extract GPS coordinates from an image and
      # call firefox with google maps url if the GPS info exists
    gps2url "$filename" &
    ;;

  ^*)
    # Rename image directly from qiv. The timestamp of the current image will be
    # automatically embedded in the new filename. This action is invoked by typing:
    #
    #	^<new_img_name><RETURN>
    #
    # Echoing the `NEWNAME=new_img_name` line signals qiv to update it's file list
    # with the new filename.
    img_timestamp=$(date -r `stat -f '%m' "$filename"` +'%y%m%d%H%M%S')
    new_img_name=${pressed_key#^}
    new_img_name=`echo "$new_img_name" | tr ' ' '_'`
    new_img_name=${new_img_name%.[Jj][Pp][Gg]}-${img_timestamp}.jpg

    [[ -f "$new_img_name" ]] && exit 1
    mv "$filename" "$new_img_name"
    echo "NEWNAME=$new_img_name"
    ;;

  V)
    qiv -h
    ;;

  *)
    cat <<-EOF
	Commands:
	  0 		show EXIF header
	  6 		edit JPEG comment
	  7 		start GIMP to edit current image
	  8 		lossless rotate left
	  9 		lossless rotate right
	  ^8		non-perfect rotate left  (use if '8' fails)
	  ^9		non-perfect rotate right (use if '9' fails)
	  ^STRING 	rename current file to STRING

	  Within qiv you simply press a key from 0-9 or any other unused key!
	  "$pressed_key" not defined yet.  Quitting.
	EOF
    exit 1
esac


exit 0