source: extensions/AMetaData/JpegMetaData/Readers/GpsReader.class.php @ 26187

Last change on this file since 26187 was 17554, checked in by grum, 12 years ago

feature:2701
bug:2702
bug:2720
bug:2722

  • Property svn:executable set to *
File size: 5.9 KB
Line 
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    protected $schema = Schemas::EXIF;
57
58    function __destruct()
59    {
60      parent::__destruct();
61    }
62
63    /**
64     * initialize the definition of the GPS tags
65     */
66    protected function initializeTagDef()
67    {
68      $this->tagDef = new GpsTags();
69    }
70
71    /**
72     * this function do the interpretation of specials tags and overrides the
73     * IfdReader function
74    */
75    protected function processSpecialTag($tagId, $values, $type, $valuesOffset=0)
76    {
77      switch($tagId)
78      {
79        case 0x0000: // Version
80          if(isset($values[0]) and isset($values[1]) and isset($values[2]) and isset($values[3]))
81          {
82            $returned=sprintf("%d.%d.%d.%d", $values[0], $values[1], $values[2], $values[3]);
83          }
84          else
85          {
86            $returned='unknown';
87          }
88
89          break;
90        case 0x0001: // GPSLatitudeRef
91        case 0x0003: // GPSLongitudeRef
92        case 0x0013: // GPSDestLatitudeRef
93        case 0x0015: // GPSDestLongitudeRef
94          $tag=$this->tagDef->getTagById($tagId);
95          $key=substr($values, 0, 1);
96          if(array_key_exists($key, $tag['tagValues.special']))
97          {
98            $returned=$tag['tagValues.special'][$key];
99          }
100          else
101          {
102            $returned="";
103          }
104          break;
105        case 0x0002: // GPSLatitude
106        case 0x0004: // GPSLongitude
107        case 0x0014: // GPSDestLatitude
108        case 0x0016: // GPSDestLongitude
109          /*
110           * converted in degrees, minutes and seconds
111           */
112          if(isset($values[0]) and isset($values[1]) and isset($values[2]))
113          {
114            $returned=ConvertData::toDMS($values[0], $values[1], $values[2]);
115          }
116          else
117          {
118            $returned="";
119          }
120          break;
121        case 0x0006: // GPSAltitude
122        case 0x000D: // GPSSpeed
123        case 0x000F: // GPSTrack
124        case 0x0011: // GPSImgDirection
125        case 0x0018: // GPSDestBearing
126        case 0x001A: // GPSDestDistance
127          if(isset($values[0]) and isset($values[1]))
128          {
129            if($values[1]==0) $values[1]=1;
130            $returned=round($values[0]/$values[1],2);
131          }
132          else
133          {
134            $returned=0;
135          }
136          break;
137        case 0x0008: // GPSSatellites
138        case 0x0012: // GPSMapDatum
139        case 0x001B: // GPSProcessingMethod => not sure about the string format...
140        case 0x001C: // GPSAreaInformation => not sure about the string format...
141          $returned=ConvertData::toStrings($values);
142          break;
143        case 0x0009: // GPSStatus
144        case 0x000A: // GPSMeasureMode
145        case 0x000C: // GPSSpeedRef
146        case 0x0019: // GPSDestDistanceRef
147        case 0x000E: // GPSTrackRef
148        case 0x0010: // GPSImgDirectionRef
149        case 0x0017: // GPSDestBearingRef
150          $tag=$this->tagDef->getTagById(0x0009);
151          $key=substr($values,0,1);
152          if(array_key_exists($key, $tag['tagValues.special']))
153          {
154            $returned=$tag['tagValues.special'][$key];
155          }
156          else
157          {
158            $returned=$tag['tagValues.special']['unknown'];
159          }
160          break;
161        case 0x001D: // GPSDateStamp
162          $returned=ConvertData::toDateTime($values);
163          break;
164        default:
165          $returned="Not yet implemented;".ConvertData::toHexDump($tagId, ByteType::USHORT)." => ".ConvertData::toHexDump($values, $type);
166          break;
167      }
168      return($returned);
169    }
170
171  }
172
173
174?>
Note: See TracBrowser for help on using the repository browser.