xsay: add support for sselp and xclip; output error message
[grml-scripts.git] / usr_bin / exifinfo
1 :
2 ##########################################################################
3 # Title      :  exifinfo - print EXIF information of an image file
4 # Author     :  Heiner Steven <heiner.steven@odn.de>
5 # Date       :  2004-01-09
6 # Category   :  Graphics
7 # Requires   :  identify
8 # SCCS-Id.   :  @(#) exifinfo   1.3 04/10/13
9 ##########################################################################
10 # Description
11 #
12 # Caveats
13 #    o  EXIF tags that would result in invalid shell variable names
14 #       should be rewritten, e.g. by replacing invalid characters with a
15 #       '_' character
16 #    o  Individual tag names (e.g. "ImageWidth") should be allowed
17 #
18 # Bibiliography
19 #    o  exif.org: "Specifications"
20 #       http://park2.wakwak.com/~tsuruzoh/Computer/Digicams/exif-e.html
21 #    o  TsuruZoh Tachibanaya: "Description of Exif file format",
22 #       http://park2.wakwak.com/~tsuruzoh/Computer/Digicams/exif-e.html
23 #
24 # Output example (identify 5.5.4)
25 #   EXIF_Make='EASTMAN KODAK COMPANY'
26 #   EXIF_Model='KODAK DX4530 ZOOM DIGITAL CAMERA'
27 #   EXIF_Orientation='1'
28 #   EXIF_XResolution='230/1'
29 #   EXIF_YResolution='230/1'
30 #   EXIF_ResolutionUnit='2'
31 #   EXIF_YCbCrPositioning='1'
32 #   EXIF_ExifOffset='506'
33 #   EXIF_ExposureTime='1/30'
34 #   EXIF_FNumber='28/10'
35 #   EXIF_ExposureProgram='2'
36 #   EXIF_ExifVersion='0220'
37 #   EXIF_DateTimeOriginal='2003:01:03 08:41:52'
38 #   EXIF_DateTimeDigitized='2003:01:03 08:41:52'
39 #   EXIF_ComponentsConfiguration='...'
40 #   EXIF_ShutterSpeedValue='50/10'
41 #   EXIF_ApertureValue='3/1'
42 #   EXIF_ExposureBiasValue='0/1000'
43 #   EXIF_MaxApertureValue='30/10'
44 #   EXIF_MeteringMode='5'
45 #   EXIF_LightSource='0'
46 #   EXIF_Flash='25'
47 #   EXIF_FocalLength='80/10'
48 #   EXIF_MakerNote='KDK0002IDX4530  ..'
49 #   EXIF_FlashPixVersion='0100'
50 #   EXIF_ColorSpace='1'
51 #   EXIF_ExifImageWidth='2580'
52 #   EXIF_ExifImageLength='1932'
53 #   EXIF_InteroperabilityOffset='2320'
54 #   EXIF_unknown='R98'
55 #   EXIF_unknown='0100'
56 #   EXIF_ExposureIndex='140/1'
57 #   EXIF_SensingMethod='2'
58 #   EXIF_FileSource='.'
59 #   EXIF_SceneType='.'
60 #   EXIF_unknown='0'
61 #   EXIF_unknown='0'
62 #   EXIF_unknown='0'
63 #   EXIF_unknown='0/100'
64 #   EXIF_unknown='38'
65 #   EXIF_unknown='0'
66 #   EXIF_unknown='1'
67 #   EXIF_unknown='0'
68 #   EXIF_unknown='0'
69 #   EXIF_unknown='0'
70 #   EXIF_unknown='0'
71 ##########################################################################
72
73 PN=`basename "$0"`                      # Program name
74 VER='1.3'
75
76 usage () {
77     echo >&2 "$PN - print EXIF information of an image file, $VER
78 usage: $PN [-p prefix] image [image ...]
79     -p:  variable prefix (default is \"EXIF_\")
80
81 Prints the EXIF information from the image files. The output is printed
82 as "var=value" pairs in a way suitable as input to the shell, e.g.
83
84         eval \`$PN image.jpg\`
85
86 can be used to set variables e.g. \"EXIF_ExifVersion\". Note that EXIF
87 tags with names that would be invalid shell variable names are silently
88 ignored."
89     exit 1
90 }
91
92 msg () {
93     for MsgLine
94     do echo "$PN: $MsgLine" >&2
95     done
96 }
97
98 fatal () { msg "$@"; exit 1; }
99
100 Prefix=
101 while getopts :hp: opt
102 do
103     case "$opt" in
104         p)      Prefix=$OPTARG;;
105         h)      usage;;
106         ?)      usage;;
107     esac
108 done
109 shift `expr $OPTIND - 1`
110
111 [ $# -lt 1 ] && usage
112
113 prefix=${Prefix:-EXIF_}
114 info='*'
115
116 for file
117 do
118     # Explanation of the "sed" expressions:
119     #    o  remove all lines not containing a "="
120     #    o  remove all lines containing tag names that would form invalid
121     #       shell variable names
122     #    o  quote all apostrophy characters ' as '\''
123     #    o  add an apostrophy at the front and the end of the value
124     #       string
125     #    o  write the variable name prefix in front of each variable
126
127     identify -format "%[EXIF:$info]" "$file" |
128         sed \
129                 -e '/^[^=]*$/d'         \
130                 -e '/[^A-Za-z0-9_=][^=]*=/d'    \
131                 -e "s/'/'\\\\''/g"      \
132                 -e "s/=/='/"            \
133                 -e "s/\$/'/"            \
134                 -e "s/^/$prefix/"
135 done