1 | <?php |
---|
2 | /* |
---|
3 | * --:: JPEG MetaDatas ::------------------------------------------------------- |
---|
4 | * |
---|
5 | * Author : Grum |
---|
6 | * email : grum at piwigo.org |
---|
7 | * website : http://photos.grum.fr |
---|
8 | * |
---|
9 | * << May the Little SpaceFrog be with you ! >> |
---|
10 | * |
---|
11 | * |
---|
12 | * +-----------------------------------------------------------------------+ |
---|
13 | * | JpegMetaData - a PHP based Jpeg Metadata manager | |
---|
14 | * +-----------------------------------------------------------------------+ |
---|
15 | * | Copyright(C) 2010 Grum - http://www.grum.fr | |
---|
16 | * +-----------------------------------------------------------------------+ |
---|
17 | * | This program is free software; you can redistribute it and/or modify | |
---|
18 | * | it under the terms of the GNU General Public License as published by | |
---|
19 | * | the Free Software Foundation | |
---|
20 | * | | |
---|
21 | * | This program is distributed in the hope that it will be useful, but | |
---|
22 | * | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
23 | * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
24 | * | General Public License for more details. | |
---|
25 | * | | |
---|
26 | * | You should have received a copy of the GNU General Public License | |
---|
27 | * | along with this program; if not, write to the Free Software | |
---|
28 | * | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
29 | * | USA. | |
---|
30 | * +-----------------------------------------------------------------------+ |
---|
31 | * |
---|
32 | * |
---|
33 | * ----------------------------------------------------------------------------- |
---|
34 | * |
---|
35 | * The GpsReader class is dedicated to read GPS tags from a sub IFD structure |
---|
36 | * |
---|
37 | * ======> See IfdReader.class.php to know more about an IFD structure <======== |
---|
38 | * |
---|
39 | * ----------------------------------------------------------------------------- |
---|
40 | * |
---|
41 | * .. Notes .. |
---|
42 | * |
---|
43 | * |
---|
44 | * The GpsReader class is derived from the IfdReader class. |
---|
45 | * |
---|
46 | * ========> See IfdReader.class.php to know more about common methods <======== |
---|
47 | * |
---|
48 | * ----------------------------------------------------------------------------- |
---|
49 | */ |
---|
50 | |
---|
51 | require_once(JPEG_METADATA_DIR."TagDefinitions/GpsTags.class.php"); |
---|
52 | require_once(JPEG_METADATA_DIR."Readers/MakerNotesReader.class.php"); |
---|
53 | |
---|
54 | class GpsReader extends IfdReader |
---|
55 | { |
---|
56 | function __destruct() |
---|
57 | { |
---|
58 | parent::__destruct(); |
---|
59 | } |
---|
60 | |
---|
61 | /** |
---|
62 | * initialize the definition of the GPS tags |
---|
63 | */ |
---|
64 | protected function initializeTagDef() |
---|
65 | { |
---|
66 | $this->tagDef = new GpsTags(); |
---|
67 | } |
---|
68 | |
---|
69 | /** |
---|
70 | * this function do the interpretation of specials tags and overrides the |
---|
71 | * IfdReader function |
---|
72 | */ |
---|
73 | protected function processSpecialTag($tagId, $values, $type, $valuesOffset=0) |
---|
74 | { |
---|
75 | switch($tagId) |
---|
76 | { |
---|
77 | case 0x0000: // Version |
---|
78 | $returned=sprintf("%d.%d.%d.%d", $values[0], $values[1], $values[2], $values[3]); |
---|
79 | break; |
---|
80 | case 0x0001: // GPSLatitudeRef |
---|
81 | case 0x0003: // GPSLongitudeRef |
---|
82 | case 0x0013: // GPSDestLatitudeRef |
---|
83 | case 0x0015: // GPSDestLongitudeRef |
---|
84 | $tag=$this->tagDef->getTagById($tagId); |
---|
85 | $key=substr($values, 0, 1); |
---|
86 | if(array_key_exists($key, $tag['tagValues.special'])) |
---|
87 | { |
---|
88 | $returned=$tag['tagValues.special'][$key]; |
---|
89 | } |
---|
90 | else |
---|
91 | { |
---|
92 | $returned=""; |
---|
93 | } |
---|
94 | break; |
---|
95 | case 0x0002: // GPSLatitude |
---|
96 | case 0x0004: // GPSLongitude |
---|
97 | case 0x0014: // GPSDestLatitude |
---|
98 | case 0x0016: // GPSDestLongitude |
---|
99 | /* |
---|
100 | * converted in degrees, minutes and seconds |
---|
101 | */ |
---|
102 | $returned=ConvertData::toDMS($values[0], $values[1], $values[2]); |
---|
103 | break; |
---|
104 | case 0x0006: // GPSAltitude |
---|
105 | case 0x000D: // GPSSpeed |
---|
106 | case 0x000F: // GPSTrack |
---|
107 | case 0x0011: // GPSImgDirection |
---|
108 | case 0x0018: // GPSDestBearing |
---|
109 | case 0x001A: // GPSDestDistance |
---|
110 | if($values[1]==0) $values[1]=1; |
---|
111 | $returned=round($values[0]/$values[1],2); |
---|
112 | break; |
---|
113 | case 0x0008: // GPSSatellites |
---|
114 | case 0x0012: // GPSMapDatum |
---|
115 | case 0x001B: // GPSProcessingMethod => not sure about the string format... |
---|
116 | case 0x001C: // GPSAreaInformation => not sure about the string format... |
---|
117 | $returned=ConvertData::toStrings($values); |
---|
118 | break; |
---|
119 | case 0x0009: // GPSStatus |
---|
120 | case 0x000A: // GPSMeasureMode |
---|
121 | case 0x000C: // GPSSpeedRef |
---|
122 | case 0x0019: // GPSDestDistanceRef |
---|
123 | case 0x000E: // GPSTrackRef |
---|
124 | case 0x0010: // GPSImgDirectionRef |
---|
125 | case 0x0017: // GPSDestBearingRef |
---|
126 | $tag=$this->tagDef->getTagById(0x0009); |
---|
127 | $key=substr($values,0,1); |
---|
128 | if(array_key_exists($key, $tag['tagValues.special'])) |
---|
129 | { |
---|
130 | $returned=$tag['tagValues.special'][$key]; |
---|
131 | } |
---|
132 | else |
---|
133 | { |
---|
134 | $returned=$tag['tagValues.special']['unknown']; |
---|
135 | } |
---|
136 | break; |
---|
137 | case 0x001D: // GPSDateStamp |
---|
138 | $returned=ConvertData::toDateTime($values); |
---|
139 | break; |
---|
140 | default: |
---|
141 | $returned="Not yet implemented;".ConvertData::toHexDump($tagId, ByteType::USHORT)." => ".ConvertData::toHexDump($values, $type); |
---|
142 | break; |
---|
143 | } |
---|
144 | return($returned); |
---|
145 | } |
---|
146 | |
---|
147 | } |
---|
148 | |
---|
149 | |
---|
150 | ?> |
---|