| 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 XmpReader class is the dedicated class to read XMP from the APP1 segment |
|---|
| 36 | * |
|---|
| 37 | * ----------------------------------------------------------------------------- |
|---|
| 38 | * |
|---|
| 39 | * .. Notes .. |
|---|
| 40 | * |
|---|
| 41 | * The XmpReader class is derived from the GenericReader class. |
|---|
| 42 | * |
|---|
| 43 | * ======> See GenericReader.class.php to know more about common methods <====== |
|---|
| 44 | * |
|---|
| 45 | * ----------------------------------------------------------------------------- |
|---|
| 46 | */ |
|---|
| 47 | |
|---|
| 48 | require_once(JPEG_METADATA_DIR."Common/Data.class.php"); |
|---|
| 49 | require_once(JPEG_METADATA_DIR."Common/XmlData.class.php"); |
|---|
| 50 | require_once(JPEG_METADATA_DIR."Readers/GenericReader.class.php"); |
|---|
| 51 | require_once(JPEG_METADATA_DIR."TagDefinitions/XmpTags.class.php"); |
|---|
| 52 | |
|---|
| 53 | class XmpReader extends GenericReader |
|---|
| 54 | { |
|---|
| 55 | protected $schema = Schemas::XMP; |
|---|
| 56 | |
|---|
| 57 | private $xmlData = NULL; |
|---|
| 58 | |
|---|
| 59 | private $xmpTag2Exif = NULL; |
|---|
| 60 | |
|---|
| 61 | /** |
|---|
| 62 | * The constructor needs, like the ancestor, the datas to be parsed |
|---|
| 63 | * |
|---|
| 64 | * @param String $data |
|---|
| 65 | */ |
|---|
| 66 | function __construct($data) |
|---|
| 67 | { |
|---|
| 68 | /** |
|---|
| 69 | * XML data are given from an APP1 segement. |
|---|
| 70 | * |
|---|
| 71 | * The XMP header ends with a \x00 char, so XML data can be extracted |
|---|
| 72 | * after the \x00 char |
|---|
| 73 | * |
|---|
| 74 | */ |
|---|
| 75 | $this->data=explode("\x00", $data); |
|---|
| 76 | if(count($this->data)>1) |
|---|
| 77 | { |
|---|
| 78 | $this->data=$this->data[1]; |
|---|
| 79 | } |
|---|
| 80 | else |
|---|
| 81 | { |
|---|
| 82 | $this->data=""; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | parent::__construct($this->data); |
|---|
| 86 | |
|---|
| 87 | $this->xmpTag2Exif = new XmpTag2Exif("", 0, 0); |
|---|
| 88 | |
|---|
| 89 | $this->xmlData = new XmlData($this->data->readASCII(-1,0)); |
|---|
| 90 | $this->tagDef = new XmpTags(); |
|---|
| 91 | |
|---|
| 92 | $this->loadTags(); |
|---|
| 93 | |
|---|
| 94 | $this->isValid = $this->xmlData->isValid(); |
|---|
| 95 | $this->isLoaded = $this->xmlData->isLoaded(); |
|---|
| 96 | |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | function __destruct() |
|---|
| 100 | { |
|---|
| 101 | unset($this->xmlData); |
|---|
| 102 | unset($this->xmpTag2Exif); |
|---|
| 103 | parent::__destruct(); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | public function toString() |
|---|
| 107 | { |
|---|
| 108 | $returned=$this->data->readASCII(-1,0); |
|---|
| 109 | return($returned); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | /** |
|---|
| 113 | * This function load tags from the xml tree |
|---|
| 114 | */ |
|---|
| 115 | private function loadTags() |
|---|
| 116 | { |
|---|
| 117 | if($this->xmlData->hasNodes()) |
|---|
| 118 | { |
|---|
| 119 | $this->processNode($this->xmlData->getFirstNode()); |
|---|
| 120 | } |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | /** |
|---|
| 124 | * this function analyze the node properties |
|---|
| 125 | * - attributes are converted in Tag through a call to the addTag function |
|---|
| 126 | * - childs are processed by a specific call to the processChildNode |
|---|
| 127 | * function |
|---|
| 128 | * - next node is processed by a recursive call |
|---|
| 129 | * |
|---|
| 130 | * @param XmlNode $node |
|---|
| 131 | */ |
|---|
| 132 | private function processNode($node) |
|---|
| 133 | { |
|---|
| 134 | if(!is_null($node)) |
|---|
| 135 | { |
|---|
| 136 | $node->setName($this->processNodeName($node->getName())); |
|---|
| 137 | |
|---|
| 138 | foreach($node->getAttributes() as $key => $val) |
|---|
| 139 | { |
|---|
| 140 | $val['name']=$this->processNodeName($val['name']); |
|---|
| 141 | $this->addTag($val['name'], $val['value']); |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | if(!is_null($node->getValue())) |
|---|
| 145 | { |
|---|
| 146 | $this->addTag($node->getName(), $node->getValue()); |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | if($node->hasChilds()) |
|---|
| 150 | { |
|---|
| 151 | $this->processChildNode($node); |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | $this->processNode($node->getNextNode()); |
|---|
| 155 | } |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | /** |
|---|
| 160 | * 'xap' schemas have to be interpreted as a 'xmp' schemas |
|---|
| 161 | * so, this function rename all 'xap' nodes in 'xmp' nodes |
|---|
| 162 | * |
|---|
| 163 | * @param String $nodeName |
|---|
| 164 | */ |
|---|
| 165 | private function processNodeName($nodeName) |
|---|
| 166 | { |
|---|
| 167 | $name=preg_replace(Array("/^(xap:)/", "/^(xapMM:)/"), Array("xmp:", "xmpMM:"), $nodeName); |
|---|
| 168 | |
|---|
| 169 | return($name); |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | /** |
|---|
| 174 | * childs node are 'seq', 'alt' or 'bag' type and needs a specific |
|---|
| 175 | * interpretation |
|---|
| 176 | * |
|---|
| 177 | * this function process this kind of data, and add it in the Tag entries |
|---|
| 178 | * |
|---|
| 179 | * if child node is not a special a specific node, process it as a normal |
|---|
| 180 | * node |
|---|
| 181 | * |
|---|
| 182 | * @param XmlNode $node |
|---|
| 183 | */ |
|---|
| 184 | private function processChildNode($node) |
|---|
| 185 | { |
|---|
| 186 | switch($node->getName()) |
|---|
| 187 | { |
|---|
| 188 | /* |
|---|
| 189 | * child must be 'rdf:Seq', 'rdf:Bag' or 'rdf:Alt' |
|---|
| 190 | */ |
|---|
| 191 | case "dc:contributor" : // bag |
|---|
| 192 | case "dc:creator" : // seq |
|---|
| 193 | case "dc:date" : // seq |
|---|
| 194 | case "dc:description" : // alt |
|---|
| 195 | case "dc:language" : // bag |
|---|
| 196 | case "dc:publisher" : // bag |
|---|
| 197 | case "dc:relation" : // bag |
|---|
| 198 | case "dc:rights" : // alt |
|---|
| 199 | case "dc:subject" : // bag |
|---|
| 200 | case "dc:title" : // alt |
|---|
| 201 | case "dc:Type" : // bag |
|---|
| 202 | case "xmp:Advisory" : // bag |
|---|
| 203 | case "xmp:Identifier" : // bag |
|---|
| 204 | case "xmp:Thumbnails" : // alt |
|---|
| 205 | case "xmpRights:Owner" : // bag |
|---|
| 206 | case "xmpRights:UsageTerms" : // alt |
|---|
| 207 | case "xmpMM:History" : // seq |
|---|
| 208 | case "xmpMM:Versions" : // seq |
|---|
| 209 | case "xmpBJ:JobRef" : // bag |
|---|
| 210 | case "xmpTPg:Fonts" : // bag |
|---|
| 211 | case "xmpTPg:Colorants" : // seq |
|---|
| 212 | case "xmpTPg:PlateNames" : // seq |
|---|
| 213 | case "photoshop:SupplementalCategories" : // bag |
|---|
| 214 | case "crs:ToneCurve" : // seq |
|---|
| 215 | case "tiff:BitsPerSample" : // seq |
|---|
| 216 | case "tiff:YCbCrSubSampling" : // seq |
|---|
| 217 | case "tiff:TransferFunction" : // seq |
|---|
| 218 | case "tiff:WhitePoint" : // seq |
|---|
| 219 | case "tiff:PrimaryChromaticities" : // seq |
|---|
| 220 | case "tiff:YCbCrCoefficients" : // seq |
|---|
| 221 | case "tiff:ReferenceBlackWhite" : // seq |
|---|
| 222 | case "tiff:ImageDescription" : // alt |
|---|
| 223 | case "tiff:Copyright" : // alt |
|---|
| 224 | case "exif:ComponentsConfiguration" : // seq |
|---|
| 225 | case "exif:UserComment" : // alt |
|---|
| 226 | case "exif:ISOSpeedRatings" : // seq |
|---|
| 227 | case "exif:SubjectArea" : // seq |
|---|
| 228 | case "exif:SubjectLocation" : // seq |
|---|
| 229 | case "Iptc4xmpCore:Scene": //bag |
|---|
| 230 | case "Iptc4xmpCore:SubjectCode": //bag |
|---|
| 231 | case "digiKam:TagsList": //seq |
|---|
| 232 | $child=$node->getFirstChild(); |
|---|
| 233 | switch($child->getName()) |
|---|
| 234 | { |
|---|
| 235 | case "rdf:Seq": |
|---|
| 236 | $type="seq"; |
|---|
| 237 | break; |
|---|
| 238 | case "rdf:Bag": |
|---|
| 239 | $type="bag"; |
|---|
| 240 | break; |
|---|
| 241 | case "rdf:Alt": |
|---|
| 242 | $type="alt"; |
|---|
| 243 | break; |
|---|
| 244 | default: |
|---|
| 245 | $type="n/a"; |
|---|
| 246 | break; |
|---|
| 247 | } |
|---|
| 248 | if($type=="seq" or $type=="bag" or $type=="alt") |
|---|
| 249 | { |
|---|
| 250 | $value=Array('type' => $type, 'values' => Array()); |
|---|
| 251 | $childNode=$child->getFirstChild(); |
|---|
| 252 | while(!is_null($childNode)) |
|---|
| 253 | { |
|---|
| 254 | if($childNode->getName() == "rdf:li") |
|---|
| 255 | { |
|---|
| 256 | if($type=="alt") |
|---|
| 257 | { |
|---|
| 258 | $attributes=$childNode->getAttributes(); |
|---|
| 259 | if(count($attributes)>0) |
|---|
| 260 | { |
|---|
| 261 | $attributes=$attributes[0]; |
|---|
| 262 | } |
|---|
| 263 | else |
|---|
| 264 | { |
|---|
| 265 | $attributes="n/a"; |
|---|
| 266 | } |
|---|
| 267 | $value['values'][]=Array('type' => $attributes, 'value' => $childNode->getValue()); |
|---|
| 268 | } |
|---|
| 269 | else |
|---|
| 270 | { |
|---|
| 271 | $value['values'][]=$childNode->getValue(); |
|---|
| 272 | } |
|---|
| 273 | } |
|---|
| 274 | $childNode=$childNode->getNextNode(); |
|---|
| 275 | } |
|---|
| 276 | $this->addTag($node->getName(), $value); |
|---|
| 277 | } |
|---|
| 278 | unset($child); |
|---|
| 279 | break; |
|---|
| 280 | default: |
|---|
| 281 | $this->processNode($node->getFirstChild()); |
|---|
| 282 | break; |
|---|
| 283 | } |
|---|
| 284 | } |
|---|
| 285 | |
|---|
| 286 | /** |
|---|
| 287 | * add a Tag to the entries. |
|---|
| 288 | * name and value are needed, the function made the rest (interpret the |
|---|
| 289 | * value into a 'human readable' value) |
|---|
| 290 | * |
|---|
| 291 | * @param String $name : the name of the tag |
|---|
| 292 | * @param $value : can be of any type |
|---|
| 293 | */ |
|---|
| 294 | private function addTag($name, $value) |
|---|
| 295 | { |
|---|
| 296 | $tag=new Tag($name, $value, $name); |
|---|
| 297 | |
|---|
| 298 | if($this->tagDef->tagIdExists($name)) |
|---|
| 299 | { |
|---|
| 300 | $tagProperties=$this->tagDef->getTagById($name); |
|---|
| 301 | |
|---|
| 302 | $tag->setKnown(true); |
|---|
| 303 | $tag->setImplemented($tagProperties['implemented']); |
|---|
| 304 | $tag->setTranslatable($tagProperties['translatable']); |
|---|
| 305 | $tag->setSchema($this->schema); |
|---|
| 306 | |
|---|
| 307 | if(array_key_exists('name', $tagProperties)) |
|---|
| 308 | { |
|---|
| 309 | $tag->setName($tagProperties['name']); |
|---|
| 310 | } |
|---|
| 311 | |
|---|
| 312 | /* |
|---|
| 313 | * if there is values defined for the tag, analyze it |
|---|
| 314 | */ |
|---|
| 315 | if(array_key_exists('tagValues', $tagProperties)) |
|---|
| 316 | { |
|---|
| 317 | if(array_key_exists($value, $tagProperties['tagValues'])) |
|---|
| 318 | { |
|---|
| 319 | $tag->setLabel($tagProperties['tagValues'][$value]); |
|---|
| 320 | } |
|---|
| 321 | else |
|---|
| 322 | { |
|---|
| 323 | $tag->setLabel("[unknown value '".$value."']"); |
|---|
| 324 | } |
|---|
| 325 | } |
|---|
| 326 | else |
|---|
| 327 | { |
|---|
| 328 | /* |
|---|
| 329 | * there is no values defined for the tag, analyzing it with dedicated |
|---|
| 330 | * function |
|---|
| 331 | */ |
|---|
| 332 | if(array_key_exists('exifTag', $tagProperties)) |
|---|
| 333 | { |
|---|
| 334 | $tag->setLabel($this->xmp2Exif($name, $tagProperties['exifTag'], $value)); |
|---|
| 335 | } |
|---|
| 336 | else |
|---|
| 337 | { |
|---|
| 338 | $tag->setLabel($this->processSpecialTag($name, $value)); |
|---|
| 339 | } |
|---|
| 340 | |
|---|
| 341 | } |
|---|
| 342 | unset($tagProperties); |
|---|
| 343 | } |
|---|
| 344 | |
|---|
| 345 | $this->entries[]=$tag; |
|---|
| 346 | unset($tag); |
|---|
| 347 | } |
|---|
| 348 | |
|---|
| 349 | /** |
|---|
| 350 | * this function do the interpretation of specials tags |
|---|
| 351 | * |
|---|
| 352 | * the function return the interpreted value for the tag |
|---|
| 353 | * |
|---|
| 354 | * @param $name : the name of the tag |
|---|
| 355 | * @param $value : 'raw' value to be interpreted |
|---|
| 356 | */ |
|---|
| 357 | private function processSpecialTag($name, $value) |
|---|
| 358 | { |
|---|
| 359 | /* |
|---|
| 360 | * Note : exif & tiff values are not processed in this function |
|---|
| 361 | */ |
|---|
| 362 | switch($name) |
|---|
| 363 | { |
|---|
| 364 | case "x:xmptk": |
|---|
| 365 | case "aux:Lens": |
|---|
| 366 | case "aux:Firmware": |
|---|
| 367 | case "aux:SerialNumber": |
|---|
| 368 | case "dc:coverage": |
|---|
| 369 | case "dc:format": |
|---|
| 370 | case "dc:identifier": |
|---|
| 371 | case "dc:relation": |
|---|
| 372 | case "dc:source": |
|---|
| 373 | case "dc:title": |
|---|
| 374 | case "dc:CreatorTool": |
|---|
| 375 | case "xmp:BaseURL": |
|---|
| 376 | case "xmp:CreatorTool": |
|---|
| 377 | case "xmp:Label": |
|---|
| 378 | case "xmp:Nickname": |
|---|
| 379 | case "xmp:Rating:": |
|---|
| 380 | case "xmpRights:Certificate": |
|---|
| 381 | case "xmpRights:Marked": |
|---|
| 382 | case "xmpRights:UsageTerms": |
|---|
| 383 | case "xmpRights:WebStatement": |
|---|
| 384 | case "xmpMM:DocumentID": |
|---|
| 385 | case "xmpMM:InstanceID": |
|---|
| 386 | case "xmpMM:Manager": |
|---|
| 387 | case "xmpMM:ManageTo": |
|---|
| 388 | case "xmpMM:ManageUI": |
|---|
| 389 | case "xmpMM:ManagerVariant": |
|---|
| 390 | case "xmpMM:RenditionParams": |
|---|
| 391 | case "xmpMM:VersionID": |
|---|
| 392 | case "xmpMM:LastURL": |
|---|
| 393 | case "photoshop:AuthorsPosition": |
|---|
| 394 | case "photoshop:CaptionWriter": |
|---|
| 395 | case "photoshop:Category": |
|---|
| 396 | case "photoshop:City": |
|---|
| 397 | case "photoshop:Country": |
|---|
| 398 | case "photoshop:Credit": |
|---|
| 399 | case "photoshop:Headline": |
|---|
| 400 | case "photoshop:Instructions": |
|---|
| 401 | case "photoshop:Source": |
|---|
| 402 | case "photoshop:State": |
|---|
| 403 | case "photoshop:TransmissionReference": |
|---|
| 404 | case "photoshop:ICCProfile": |
|---|
| 405 | case "crs:AutoBrightness": |
|---|
| 406 | case "crs:AutoContrast": |
|---|
| 407 | case "crs:AutoExposure": |
|---|
| 408 | case "crs:AutoShadows": |
|---|
| 409 | case "crs:BlueHue": |
|---|
| 410 | case "crs:BlueSaturation": |
|---|
| 411 | case "crs:Brightness": |
|---|
| 412 | case "crs:CameraProfile": |
|---|
| 413 | case "crs:ChromaticAberrationB": |
|---|
| 414 | case "crs:ChromaticAberrationR": |
|---|
| 415 | case "crs:ColorNoiseReduction": |
|---|
| 416 | case "crs:Contrast": |
|---|
| 417 | case "crs:CropTop": |
|---|
| 418 | case "crs:CropLeft": |
|---|
| 419 | case "crs:CropBottom": |
|---|
| 420 | case "crs:CropRight": |
|---|
| 421 | case "crs:CropAngle": |
|---|
| 422 | case "crs:CropWidth": |
|---|
| 423 | case "crs:CropHeight": |
|---|
| 424 | case "crs:Exposure": |
|---|
| 425 | case "crs:GreenHue": |
|---|
| 426 | case "crs:GreenSaturation": |
|---|
| 427 | case "crs:HasCrop": |
|---|
| 428 | case "crs:HasSettings": |
|---|
| 429 | case "crs:LuminanceSmoothing": |
|---|
| 430 | case "crs:RawFileName": |
|---|
| 431 | case "crs:RedHue": |
|---|
| 432 | case "crs:RedSaturation": |
|---|
| 433 | case "crs:Saturation": |
|---|
| 434 | case "crs:Shadows": |
|---|
| 435 | case "crs:ShadowTint": |
|---|
| 436 | case "crs:Sharpness": |
|---|
| 437 | case "crs:Temperature": |
|---|
| 438 | case "crs:Tint": |
|---|
| 439 | case "crs:Version": |
|---|
| 440 | case "crs:VignetteAmount": |
|---|
| 441 | case "crs:VignetteMidpoint": |
|---|
| 442 | case "Iptc4xmpCore:CountryCode": |
|---|
| 443 | case "Iptc4xmpCore:Location": |
|---|
| 444 | case "Iptc4xmpCore:CiEmailWork": |
|---|
| 445 | case "Iptc4xmpCore:CiUrlWork": |
|---|
| 446 | case "Iptc4xmpCore:CiTelWork": |
|---|
| 447 | case "Iptc4xmpCore:CiAdrExtadr": |
|---|
| 448 | case "Iptc4xmpCore:CiAdrPcode": |
|---|
| 449 | case "Iptc4xmpCore:CiAdrCity": |
|---|
| 450 | case "Iptc4xmpCore:CiAdrCtry": |
|---|
| 451 | $returned=$value; |
|---|
| 452 | break; |
|---|
| 453 | case "Iptc4xmpCore:IntellectualGenre": |
|---|
| 454 | $returned=explode(":", $value); |
|---|
| 455 | break; |
|---|
| 456 | case "exif:GPSLatitude": |
|---|
| 457 | case "exif:GPSLongitude": |
|---|
| 458 | case "exif:GPSDestLatitude": |
|---|
| 459 | case "exif:GPSDestLongitude": |
|---|
| 460 | $returned=Array('coord' => "", 'card'=>""); |
|---|
| 461 | preg_match_all('/(\d{1,3}),(\d{1,2})(?:\.(\d*)){0,1}(N|S|E|W)/', $value, $result); |
|---|
| 462 | $returned['coord']=$result[1][0]."° ".$result[2][0]."' "; |
|---|
| 463 | if(trim($result[3][0])!="") |
|---|
| 464 | { |
|---|
| 465 | $returned['coord'].= round(("0.".$result[3][0])*60,2)."\""; |
|---|
| 466 | } |
|---|
| 467 | switch($result[4][0]) |
|---|
| 468 | { |
|---|
| 469 | case "N": |
|---|
| 470 | $returned['card']="North"; |
|---|
| 471 | break; |
|---|
| 472 | case "S": |
|---|
| 473 | $returned['card']="South"; |
|---|
| 474 | break; |
|---|
| 475 | case "E": |
|---|
| 476 | $returned['card']="East"; |
|---|
| 477 | break; |
|---|
| 478 | case "W": |
|---|
| 479 | $returned['card']="West"; |
|---|
| 480 | break; |
|---|
| 481 | } |
|---|
| 482 | $type=ByteType::UNDEFINED; |
|---|
| 483 | break; |
|---|
| 484 | case "xmp:CreateDate": |
|---|
| 485 | case "xmp:ModifyDate": |
|---|
| 486 | case "xmp:MetadataDate": |
|---|
| 487 | case "tiff:DateTime": |
|---|
| 488 | case "photoshop:DateCreated": |
|---|
| 489 | case "Iptc4xmpCore:DateCreated": |
|---|
| 490 | $returned=ConvertData::toDateTime($value); |
|---|
| 491 | break; |
|---|
| 492 | case "dc:contributor" : // bag |
|---|
| 493 | case "dc:creator" : // seq |
|---|
| 494 | case "dc:date" : // seq |
|---|
| 495 | case "dc:description" : // alt |
|---|
| 496 | case "dc:language" : // bag |
|---|
| 497 | case "dc:publisher" : // bag |
|---|
| 498 | case "dc:relation" : // bag |
|---|
| 499 | case "dc:rights" : // alt |
|---|
| 500 | case "dc:subject" : // bag |
|---|
| 501 | case "dc:title" : // alt |
|---|
| 502 | case "dc:Type" : // bag |
|---|
| 503 | case "xmp:Advisory" : // bag |
|---|
| 504 | case "xmp:Identifier" : // bag |
|---|
| 505 | case "xmp:Thumbnails" : // alt |
|---|
| 506 | case "xmpRights:Owner" : // bag |
|---|
| 507 | case "xmpRights:UsageTerms" : // alt |
|---|
| 508 | case "xmpMM:History" : // seq |
|---|
| 509 | case "xmpMM:Versions" : // seq |
|---|
| 510 | case "xmpBJ:JobRef" : // bag |
|---|
| 511 | case "xmpTPg:Fonts" : // bag |
|---|
| 512 | case "xmpTPg:Colorants" : // seq |
|---|
| 513 | case "xmpTPg:PlateNames" : // seq |
|---|
| 514 | case "photoshop:SupplementalCategories" : // bag |
|---|
| 515 | case "crs:ToneCurve" : // seq |
|---|
| 516 | case "tiff:BitsPerSample" : // seq |
|---|
| 517 | case "tiff:YCbCrSubSampling" : // seq |
|---|
| 518 | case "tiff:TransferFunction" : // seq |
|---|
| 519 | case "tiff:WhitePoint" : // seq |
|---|
| 520 | case "tiff:PrimaryChromaticities" : // seq |
|---|
| 521 | case "tiff:YCbCrCoefficients" : // seq |
|---|
| 522 | case "tiff:ReferenceBlackWhite" : // seq |
|---|
| 523 | case "tiff:ImageDescription" : // alt |
|---|
| 524 | case "tiff:Copyright" : // alt |
|---|
| 525 | case "exif:ComponentsConfiguration" : // seq |
|---|
| 526 | case "exif:UserComment" : // alt |
|---|
| 527 | case "exif:ISOSpeedRatings" : // seq |
|---|
| 528 | case "exif:SubjectArea" : // seq |
|---|
| 529 | case "exif:SubjectLocation" : // seq |
|---|
| 530 | case "digiKam:TagsList": //seq |
|---|
| 531 | $returned=$value; |
|---|
| 532 | break; |
|---|
| 533 | case "Iptc4xmpCore:Scene": //bag |
|---|
| 534 | $tag=$this->tagDef->getTagById('Iptc4xmpCore:Scene'); |
|---|
| 535 | $returned=$value; |
|---|
| 536 | foreach($returned['values'] as $key=>$val) |
|---|
| 537 | { |
|---|
| 538 | if(array_key_exists($val, $tag['tagValues.special'])) |
|---|
| 539 | $returned['values'][$key]=$tag['tagValues.special'][$val]; |
|---|
| 540 | } |
|---|
| 541 | unset($tag); |
|---|
| 542 | break; |
|---|
| 543 | case "Iptc4xmpCore:SubjectCode": //bag |
|---|
| 544 | $returned=$value; |
|---|
| 545 | foreach($returned['values'] as $key=>$val) |
|---|
| 546 | { |
|---|
| 547 | $tmp=explode(":", $val); |
|---|
| 548 | |
|---|
| 549 | $returned['values'][$key]=Array(); |
|---|
| 550 | |
|---|
| 551 | if(count($tmp)>=1) |
|---|
| 552 | $returned['values'][$key]['IPR']=$tmp[0]; |
|---|
| 553 | |
|---|
| 554 | if(count($tmp)>=2) |
|---|
| 555 | $returned['values'][$key]['subjectCode']=$tmp[1]; |
|---|
| 556 | |
|---|
| 557 | if(count($tmp)>=3) |
|---|
| 558 | $returned['values'][$key]['subjectName']=$tmp[2]; |
|---|
| 559 | |
|---|
| 560 | if(count($tmp)>=4) |
|---|
| 561 | $returned['values'][$key]['subjectMatterName']=$tmp[3]; |
|---|
| 562 | |
|---|
| 563 | if(count($tmp)>=5) |
|---|
| 564 | $returned['values'][$key]['subjectDetailName']=$tmp[4]; |
|---|
| 565 | |
|---|
| 566 | unset($tmp); |
|---|
| 567 | } |
|---|
| 568 | break; |
|---|
| 569 | default: |
|---|
| 570 | $returned="Not yet implemented; $name"; |
|---|
| 571 | break; |
|---|
| 572 | } |
|---|
| 573 | return($returned); |
|---|
| 574 | } |
|---|
| 575 | |
|---|
| 576 | /** |
|---|
| 577 | * this function convert the value from XMP 'exif' or XMP 'tiff' data by |
|---|
| 578 | * using an instance of a XmpTag2Exif object (using exif tag object allows |
|---|
| 579 | * not coding the same things twice) |
|---|
| 580 | */ |
|---|
| 581 | private function xmp2Exif($tagName, $exifTag, $xmpValue) |
|---|
| 582 | { |
|---|
| 583 | switch($tagName) |
|---|
| 584 | { |
|---|
| 585 | /* integers */ |
|---|
| 586 | case "tiff:ImageWidth": |
|---|
| 587 | case "tiff:ImageLength": |
|---|
| 588 | case "tiff:PhotometricInterpretation": |
|---|
| 589 | case "tiff:Orientation": |
|---|
| 590 | case "tiff:SamplesPerPixel": |
|---|
| 591 | case "tiff:PlanarConfiguration": |
|---|
| 592 | case "tiff:YCbCrSubSampling": |
|---|
| 593 | case "tiff:YCbCrPositioning": |
|---|
| 594 | case "tiff:ResolutionUnit": |
|---|
| 595 | case "exif:ColorSpace": |
|---|
| 596 | case "exif:PixelXDimension": |
|---|
| 597 | case "exif:PixelYDimension": |
|---|
| 598 | case "exif:MeteringMode": |
|---|
| 599 | case "exif:LightSource": |
|---|
| 600 | case "exif:FlashEnergy": |
|---|
| 601 | case "exif:FocalPlaneResolutionUnit": |
|---|
| 602 | case "exif:SensingMethod": |
|---|
| 603 | case "exif:FileSource": |
|---|
| 604 | case "exif:SceneType": |
|---|
| 605 | case "exif:CustomRendered": |
|---|
| 606 | case "exif:ExposureMode": |
|---|
| 607 | case "exif:Balance": |
|---|
| 608 | case "exif:FocalLengthIn35mmFilm": |
|---|
| 609 | case "exif:SceneCaptureType": |
|---|
| 610 | case "exif:GainControl": |
|---|
| 611 | case "exif:Contrast": |
|---|
| 612 | case "exif:Saturation": |
|---|
| 613 | case "exif:Sharpness": |
|---|
| 614 | case "exif:SubjectDistanceRange": |
|---|
| 615 | case "exif:GPSAltitudeRef": |
|---|
| 616 | case "exif:GPSDifferential": |
|---|
| 617 | $returned=(int)$xmpValue; |
|---|
| 618 | $type=ByteType::ULONG; |
|---|
| 619 | break; |
|---|
| 620 | /* specials */ |
|---|
| 621 | case "tiff:BitsPerSample": |
|---|
| 622 | case "tiff:Compression": |
|---|
| 623 | case "tiff:TransferFunction": |
|---|
| 624 | case "tiff:WhitePoint": |
|---|
| 625 | case "tiff:PrimaryChromaticities": |
|---|
| 626 | case "tiff:YCbCrCoefficients": |
|---|
| 627 | case "tiff:ReferenceBlackWhite": |
|---|
| 628 | case "exif:ComponentsConfiguration": |
|---|
| 629 | case "exif:ExposureProgram": |
|---|
| 630 | case "exif:ISOSpeedRatings": |
|---|
| 631 | case "exif:OECF": |
|---|
| 632 | case "exif:Flash": |
|---|
| 633 | case "exif:SubjectArea": |
|---|
| 634 | case "exif:SpatialFrequencyResponse": |
|---|
| 635 | case "exif:SubjectLocation": |
|---|
| 636 | case "exif:CFAPattern": |
|---|
| 637 | case "exif:DeviceSettingDescription": |
|---|
| 638 | $returned=$xmpValue; |
|---|
| 639 | $type=ByteType::UNDEFINED; |
|---|
| 640 | break; |
|---|
| 641 | /* rational */ |
|---|
| 642 | case "tiff:XResolution": |
|---|
| 643 | case "tiff:YResolution": |
|---|
| 644 | case "exif:CompressedBitsPerPixel": |
|---|
| 645 | case "exif:ExposureTime": |
|---|
| 646 | case "exif:FNumber": |
|---|
| 647 | case "exif:ShutterSpeedValue": |
|---|
| 648 | case "exif:ApertureValue": |
|---|
| 649 | case "exif:BrightnessValue": |
|---|
| 650 | case "exif:ExposureBiasValue": |
|---|
| 651 | case "exif:MaxApertureValue": |
|---|
| 652 | case "exif:SubjectDistance": |
|---|
| 653 | case "exif:FocalLength": |
|---|
| 654 | case "exif:FocalPlaneXResolution": |
|---|
| 655 | case "exif:FocalPlaneYResolution": |
|---|
| 656 | case "exif:ExposureIndex": |
|---|
| 657 | case "exif:DigitalZoomRatio": |
|---|
| 658 | case "exif:GPSAltitude": |
|---|
| 659 | case "exif:GPSDOP": |
|---|
| 660 | case "exif:GPSSpeed": |
|---|
| 661 | case "exif:GPSTrack": |
|---|
| 662 | case "exif:GPSImgDirection": |
|---|
| 663 | case "exif:GPSDestBearing": |
|---|
| 664 | case "exif:GPSDestDistance": |
|---|
| 665 | $computed=explode("/", $xmpValue); |
|---|
| 666 | $returned=Array((int)$computed[0], (int)$computed[1]); |
|---|
| 667 | $type=ByteType::URATIONAL; |
|---|
| 668 | unset($computed); |
|---|
| 669 | break; |
|---|
| 670 | /* dates & texts */ |
|---|
| 671 | case "tiff:DateTime": |
|---|
| 672 | case "tiff:ImageDescription": |
|---|
| 673 | case "tiff:Make": |
|---|
| 674 | case "tiff:Model": |
|---|
| 675 | case "tiff:Software": |
|---|
| 676 | case "tiff:Artist": |
|---|
| 677 | case "tiff:Copyright": |
|---|
| 678 | case "exif:ExifVersion": |
|---|
| 679 | case "exif:FlashpixVersion": |
|---|
| 680 | case "exif:UserComment": |
|---|
| 681 | case "exif:RelatedSoundFile": |
|---|
| 682 | case "exif:DateTimeOriginal": |
|---|
| 683 | case "exif:DateTimeDigitized": |
|---|
| 684 | case "exif:SpectralSensitivity": |
|---|
| 685 | case "exif:ImageUniqueID": |
|---|
| 686 | case "exif:GPSVersionID": |
|---|
| 687 | case "exif:GPSTimeStamp": |
|---|
| 688 | case "exif:GPSSatellites": |
|---|
| 689 | case "exif:GPSStatus": |
|---|
| 690 | case "exif:GPSMeasureMode": |
|---|
| 691 | case "exif:GPSSpeedRef": |
|---|
| 692 | case "exif:GPSTrackRef": |
|---|
| 693 | case "exif:GPSImgDirectionRef": |
|---|
| 694 | case "exif:GPSMapDatum": |
|---|
| 695 | case "exif:GPSDestBearingRef": |
|---|
| 696 | case "exif:GPSDestDistanceRef": |
|---|
| 697 | case "exif:GPSProcessingMethod": |
|---|
| 698 | case "exif:GPSAreaInformation": |
|---|
| 699 | $returned=$xmpValue; |
|---|
| 700 | $type=ByteType::ASCII; |
|---|
| 701 | break; |
|---|
| 702 | default: |
|---|
| 703 | $returned="Unknown tag: $tagName => $xmpValue"; |
|---|
| 704 | break; |
|---|
| 705 | } |
|---|
| 706 | if(is_array($returned)) |
|---|
| 707 | { |
|---|
| 708 | if(array_key_exists('type', $returned)) |
|---|
| 709 | { |
|---|
| 710 | if($returned['type']=='alt') |
|---|
| 711 | { |
|---|
| 712 | } |
|---|
| 713 | else |
|---|
| 714 | { |
|---|
| 715 | foreach($returned['values'] as $key => $val) |
|---|
| 716 | { |
|---|
| 717 | $returned['values'][$key]['value']=$this->xmpTag2Exif->convert($exifTag, $val['value'], $type); |
|---|
| 718 | } |
|---|
| 719 | } |
|---|
| 720 | } |
|---|
| 721 | else |
|---|
| 722 | { |
|---|
| 723 | return($this->xmpTag2Exif->convert($exifTag, $returned, $type)); |
|---|
| 724 | } |
|---|
| 725 | } |
|---|
| 726 | return($returned); |
|---|
| 727 | } |
|---|
| 728 | |
|---|
| 729 | } |
|---|
| 730 | |
|---|
| 731 | /** |
|---|
| 732 | * The XmpTag2Exif is derived from the IfdReader class |
|---|
| 733 | * |
|---|
| 734 | * This function provides the public function 'convert', allowing to convert |
|---|
| 735 | * 'exif' datas in 'human readable' values |
|---|
| 736 | * |
|---|
| 737 | */ |
|---|
| 738 | class XmpTag2Exif extends IfdReader |
|---|
| 739 | { |
|---|
| 740 | public function convert($exifTag, $value, $type) |
|---|
| 741 | { |
|---|
| 742 | return($this->processSpecialTag($exifTag, $value, $type)); |
|---|
| 743 | } |
|---|
| 744 | } |
|---|
| 745 | |
|---|
| 746 | ?> |
|---|