| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
### |
| 4 |
### QUICK IMAGE VIEWER "qiv-command" file |
| 5 |
### http://qiv.spiegl.de/ |
| 6 |
### |
| 7 |
### This file will be launched by QIV if you push 0-9 (or any other free key) |
| 8 |
### NEW: Now you can use all free keys for qiv-command. |
| 9 |
### NEW: If you press "X" followed by any string, |
| 10 |
### qiv-command is called with X and this string |
| 11 |
### |
| 12 |
### Just put it in a directory that is in your path |
| 13 |
### |
| 14 |
### Note: |
| 15 |
### If the first line of the output is like "NEWNAME=xxxxxxx" then qiv |
| 16 |
### thinks that the filename of the currently displayed image has |
| 17 |
### changed to this new name and updates its internal filelist. |
| 18 |
### This is very useful when using qiv-command to rename files. |
| 19 |
|
| 20 |
# |
| 21 |
# some examples by Andy Spiegl <[email protected]> |
| 22 |
# Created: 2002-05-12 |
| 23 |
# Last change: 2021-12-14 |
| 24 |
# |
| 25 |
# more examples (renaming, jpg comments) by Clint Pachl <[email protected]> |
| 26 |
# |
| 27 |
# needs jhead to rotate JPEG without loss of Exif Jpeg headers |
| 28 |
# jhead is: |
| 29 |
# Program for extracting Digicam setting information from Exif Jpeg headers |
| 30 |
# used by most Digital Cameras. v2.6 by Matthias Wandel, Dec 26 2006 |
| 31 |
# http://www.sentex.net/~mwandel/jhead [email protected] |
| 32 |
|
| 33 |
# Syntax: qiv-command [pressed_key] [image_filename_with_full_path] |
| 34 |
pressed_key=$1 # key(s) pressed in qiv |
| 35 |
filename=$2 # image filename with full path |
| 36 |
|
| 37 |
echo "You pressed the $pressed_key key while watching $filename" |
| 38 |
|
| 39 |
case "$pressed_key" in |
| 40 |
|
| 41 |
0) |
| 42 |
# do something with the image ($2) -> |
| 43 |
# |
| 44 |
# example: copy |
| 45 |
# cp "$2" "/home/myfiles/download/"; |
| 46 |
# |
| 47 |
# example: move |
| 48 |
# mv "$2" "/home/myfiles/download/"; |
| 49 |
# echo "NEWNAME=/home/myfiles/download/$2"; |
| 50 |
# |
| 51 |
# example: show EXIF Header using "exiftool" or "jhead" |
| 52 |
# exiftool "$filename" |
| 53 |
# jhead "$filename" |
| 54 |
# more sophisticated for better infos (adjust paths!) |
| 55 |
# if [ -r $HOME/local/var/exiftool.tags.for.qiv-command ]; then |
| 56 |
# exiftool `xargs < $HOME/local/var/exiftool.tags.for.qiv-command` "$filename" \ |
| 57 |
# | grep -v -f $HOME/local/var/exiftool.grep-exclude-pattern.for.qiv-command |
| 58 |
# jhead -nofinfo "$filename" | grep -i -E '^(JPEG Quality |Caption )' |
| 59 |
# else |
| 60 |
# jhead -nofinfo "$filename" |
| 61 |
# fi |
| 62 |
|
| 63 |
echo -ne "0 was pushed.\nStart your own programs by editing the\n\"$0\" file!"; |
| 64 |
;; |
| 65 |
|
| 66 |
|
| 67 |
1|2|3|4) |
| 68 |
echo -ne "$pressed_key was pushed.\nStart your own programs by editing the\n\"$0\" file!"; |
| 69 |
;; |
| 70 |
|
| 71 |
5) |
| 72 |
# Open picture for editing with gimp. Send stdout/stderr to /dev/null, otherwise qiv will wait for gimp to end. |
| 73 |
gimp "$filename" > /dev/null 2>&1 & |
| 74 |
;; |
| 75 |
|
| 76 |
6) |
| 77 |
# Modify comment header. Fire up an xterm running EDITOR to edit comment. |
| 78 |
#xterm -e jhead -ce "$filename" |
| 79 |
jhead -ce "$filename" |
| 80 |
;; |
| 81 |
|
| 82 |
7) |
| 83 |
# Open picture for editing with gimp. Send stdout/stderr to /dev/null, otherwise qiv will wait for gimp to end. |
| 84 |
gimp "$filename" > /dev/null 2>&1 & |
| 85 |
;; |
| 86 |
|
| 87 |
8) # lossless rotation of JPG, without losing EXIF tags |
| 88 |
echo 2>&1 "Rotating to the left." |
| 89 |
jhead -cmd "jpegtran -perfect -rotate 270 -outfile &o &i" "$filename" >/dev/null |
| 90 |
# set timestamp of file to Date/Time when the photo was taken |
| 91 |
jhead -q -ft "$filename" >/dev/null |
| 92 |
;; |
| 93 |
|
| 94 |
9) # lossless rotation of JPG, without losing EXIF tags |
| 95 |
echo 2>&1 "Rotating to the right." |
| 96 |
jhead -cmd "jpegtran -perfect -rotate 90 -outfile &o &i" "$filename" >/dev/null |
| 97 |
# set timestamp of file to Date/Time when the photo was taken |
| 98 |
jhead -q -ft "$filename" >/dev/null |
| 99 |
;; |
| 100 |
|
| 101 |
# with "^"-prefix: forced (i.e. possibly NOT lossless) rotation |
| 102 |
^8) # rotate JPG, but possibly losing quality |
| 103 |
echo 2>&1 "Forcing rotation to the left." |
| 104 |
jhead -cmd "jpegtran -rotate 270 -outfile &o &i" "$filename" >/dev/null |
| 105 |
# set timestamp of file to Date/Time when the photo was taken |
| 106 |
jhead -q -ft "$filename" >/dev/null |
| 107 |
;; |
| 108 |
|
| 109 |
^9) # rotate JPG, but possibly losing quality |
| 110 |
echo 2>&1 "Forcing rotation to the right." |
| 111 |
jhead -cmd "jpegtran -rotate 90 -outfile &o &i" "$filename" >/dev/null |
| 112 |
# set timestamp of file to Date/Time when the photo was taken |
| 113 |
jhead -q -ft "$filename" >/dev/null |
| 114 |
;; |
| 115 |
|
| 116 |
^g) # call gps2url to extract GPS coordinates from an image and |
| 117 |
# call firefox with google maps url if the GPS info exists |
| 118 |
gps2url "$filename" & |
| 119 |
;; |
| 120 |
|
| 121 |
^*) |
| 122 |
# Rename image directly from qiv. The timestamp of the current image will be |
| 123 |
# automatically embedded in the new filename. This action is invoked by typing: |
| 124 |
# |
| 125 |
# ^<new_img_name><RETURN> |
| 126 |
# |
| 127 |
# Echoing the `NEWNAME=new_img_name` line signals qiv to update it's file list |
| 128 |
# with the new filename. |
| 129 |
img_timestamp=$(date -r `stat -f '%m' "$filename"` +'%y%m%d%H%M%S') |
| 130 |
new_img_name=${pressed_key#^} |
| 131 |
new_img_name=`echo "$new_img_name" | tr ' ' '_'` |
| 132 |
new_img_name=${new_img_name%.[Jj][Pp][Gg]}-${img_timestamp}.jpg |
| 133 |
|
| 134 |
[[ -f "$new_img_name" ]] && exit 1 |
| 135 |
mv "$filename" "$new_img_name" |
| 136 |
echo "NEWNAME=$new_img_name" |
| 137 |
;; |
| 138 |
|
| 139 |
V) |
| 140 |
qiv -h |
| 141 |
;; |
| 142 |
|
| 143 |
*) |
| 144 |
cat <<-EOF |
| 145 |
Commands: |
| 146 |
0 show EXIF header |
| 147 |
6 edit JPEG comment |
| 148 |
7 start GIMP to edit current image |
| 149 |
8 lossless rotate left |
| 150 |
9 lossless rotate right |
| 151 |
^8 non-perfect rotate left (use if '8' fails) |
| 152 |
^9 non-perfect rotate right (use if '9' fails) |
| 153 |
^STRING rename current file to STRING |
| 154 |
|
| 155 |
Within qiv you simply press a key from 0-9 or any other unused key! |
| 156 |
"$pressed_key" not defined yet. Quitting. |
| 157 |
EOF |
| 158 |
exit 1 |
| 159 |
esac |
| 160 |
|
| 161 |
|
| 162 |
exit 0 |