[4686] | 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 | { |
---|
[6729] | 55 | protected $schema = Schemas::XMP; |
---|
| 56 | |
---|
[4686] | 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 | { |
---|
[4705] | 101 | unset($this->xmlData); |
---|
[4686] | 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 |
---|
[6889] | 231 | case "digiKam:TagsList": //seq |
---|
[7441] | 232 | case "lr:hierarchicalSubject": //bag |
---|
[4686] | 233 | $child=$node->getFirstChild(); |
---|
| 234 | switch($child->getName()) |
---|
| 235 | { |
---|
| 236 | case "rdf:Seq": |
---|
| 237 | $type="seq"; |
---|
| 238 | break; |
---|
| 239 | case "rdf:Bag": |
---|
| 240 | $type="bag"; |
---|
| 241 | break; |
---|
| 242 | case "rdf:Alt": |
---|
| 243 | $type="alt"; |
---|
| 244 | break; |
---|
| 245 | default: |
---|
| 246 | $type="n/a"; |
---|
| 247 | break; |
---|
| 248 | } |
---|
[6986] | 249 | if($type=="seq" or $type=="bag" or $type=="alt") |
---|
[4686] | 250 | { |
---|
| 251 | $value=Array('type' => $type, 'values' => Array()); |
---|
| 252 | $childNode=$child->getFirstChild(); |
---|
| 253 | while(!is_null($childNode)) |
---|
| 254 | { |
---|
| 255 | if($childNode->getName() == "rdf:li") |
---|
| 256 | { |
---|
| 257 | if($type=="alt") |
---|
| 258 | { |
---|
| 259 | $attributes=$childNode->getAttributes(); |
---|
| 260 | if(count($attributes)>0) |
---|
| 261 | { |
---|
| 262 | $attributes=$attributes[0]; |
---|
| 263 | } |
---|
| 264 | else |
---|
| 265 | { |
---|
| 266 | $attributes="n/a"; |
---|
| 267 | } |
---|
| 268 | $value['values'][]=Array('type' => $attributes, 'value' => $childNode->getValue()); |
---|
| 269 | } |
---|
| 270 | else |
---|
| 271 | { |
---|
| 272 | $value['values'][]=$childNode->getValue(); |
---|
| 273 | } |
---|
| 274 | } |
---|
| 275 | $childNode=$childNode->getNextNode(); |
---|
| 276 | } |
---|
| 277 | $this->addTag($node->getName(), $value); |
---|
| 278 | } |
---|
[4904] | 279 | unset($child); |
---|
[4686] | 280 | break; |
---|
| 281 | default: |
---|
| 282 | $this->processNode($node->getFirstChild()); |
---|
| 283 | break; |
---|
| 284 | } |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | /** |
---|
| 288 | * add a Tag to the entries. |
---|
| 289 | * name and value are needed, the function made the rest (interpret the |
---|
| 290 | * value into a 'human readable' value) |
---|
| 291 | * |
---|
| 292 | * @param String $name : the name of the tag |
---|
| 293 | * @param $value : can be of any type |
---|
| 294 | */ |
---|
| 295 | private function addTag($name, $value) |
---|
| 296 | { |
---|
| 297 | $tag=new Tag($name, $value, $name); |
---|
| 298 | |
---|
| 299 | if($this->tagDef->tagIdExists($name)) |
---|
| 300 | { |
---|
| 301 | $tagProperties=$this->tagDef->getTagById($name); |
---|
| 302 | |
---|
[4698] | 303 | $tag->setKnown(true); |
---|
| 304 | $tag->setImplemented($tagProperties['implemented']); |
---|
| 305 | $tag->setTranslatable($tagProperties['translatable']); |
---|
[6729] | 306 | $tag->setSchema($this->schema); |
---|
[4686] | 307 | |
---|
| 308 | if(array_key_exists('name', $tagProperties)) |
---|
| 309 | { |
---|
| 310 | $tag->setName($tagProperties['name']); |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | /* |
---|
| 314 | * if there is values defined for the tag, analyze it |
---|
| 315 | */ |
---|
| 316 | if(array_key_exists('tagValues', $tagProperties)) |
---|
| 317 | { |
---|
| 318 | if(array_key_exists($value, $tagProperties['tagValues'])) |
---|
| 319 | { |
---|
| 320 | $tag->setLabel($tagProperties['tagValues'][$value]); |
---|
| 321 | } |
---|
| 322 | else |
---|
| 323 | { |
---|
[5222] | 324 | $tag->setLabel("[unknown value '".$value."']"); |
---|
[4686] | 325 | } |
---|
| 326 | } |
---|
| 327 | else |
---|
| 328 | { |
---|
| 329 | /* |
---|
| 330 | * there is no values defined for the tag, analyzing it with dedicated |
---|
| 331 | * function |
---|
| 332 | */ |
---|
| 333 | if(array_key_exists('exifTag', $tagProperties)) |
---|
| 334 | { |
---|
| 335 | $tag->setLabel($this->xmp2Exif($name, $tagProperties['exifTag'], $value)); |
---|
| 336 | } |
---|
| 337 | else |
---|
| 338 | { |
---|
| 339 | $tag->setLabel($this->processSpecialTag($name, $value)); |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | } |
---|
[4904] | 343 | unset($tagProperties); |
---|
[4686] | 344 | } |
---|
| 345 | |
---|
| 346 | $this->entries[]=$tag; |
---|
[4904] | 347 | unset($tag); |
---|
[4686] | 348 | } |
---|
| 349 | |
---|
| 350 | /** |
---|
| 351 | * this function do the interpretation of specials tags |
---|
| 352 | * |
---|
| 353 | * the function return the interpreted value for the tag |
---|
| 354 | * |
---|
| 355 | * @param $name : the name of the tag |
---|
| 356 | * @param $value : 'raw' value to be interpreted |
---|
| 357 | */ |
---|
| 358 | private function processSpecialTag($name, $value) |
---|
| 359 | { |
---|
| 360 | /* |
---|
| 361 | * Note : exif & tiff values are not processed in this function |
---|
| 362 | */ |
---|
| 363 | switch($name) |
---|
| 364 | { |
---|
| 365 | case "x:xmptk": |
---|
[4972] | 366 | case "aux:Lens": |
---|
| 367 | case "aux:Firmware": |
---|
| 368 | case "aux:SerialNumber": |
---|
[4686] | 369 | case "dc:coverage": |
---|
| 370 | case "dc:format": |
---|
| 371 | case "dc:identifier": |
---|
| 372 | case "dc:relation": |
---|
| 373 | case "dc:source": |
---|
| 374 | case "dc:title": |
---|
[4931] | 375 | case "dc:CreatorTool": |
---|
[4686] | 376 | case "xmp:BaseURL": |
---|
| 377 | case "xmp:CreatorTool": |
---|
| 378 | case "xmp:Label": |
---|
| 379 | case "xmp:Nickname": |
---|
| 380 | case "xmp:Rating:": |
---|
| 381 | case "xmpRights:Certificate": |
---|
| 382 | case "xmpRights:Marked": |
---|
| 383 | case "xmpRights:UsageTerms": |
---|
| 384 | case "xmpRights:WebStatement": |
---|
| 385 | case "xmpMM:DocumentID": |
---|
| 386 | case "xmpMM:InstanceID": |
---|
| 387 | case "xmpMM:Manager": |
---|
| 388 | case "xmpMM:ManageTo": |
---|
| 389 | case "xmpMM:ManageUI": |
---|
| 390 | case "xmpMM:ManagerVariant": |
---|
| 391 | case "xmpMM:RenditionParams": |
---|
| 392 | case "xmpMM:VersionID": |
---|
| 393 | case "xmpMM:LastURL": |
---|
| 394 | case "photoshop:AuthorsPosition": |
---|
| 395 | case "photoshop:CaptionWriter": |
---|
| 396 | case "photoshop:Category": |
---|
| 397 | case "photoshop:City": |
---|
| 398 | case "photoshop:Country": |
---|
| 399 | case "photoshop:Credit": |
---|
| 400 | case "photoshop:Headline": |
---|
| 401 | case "photoshop:Instructions": |
---|
| 402 | case "photoshop:Source": |
---|
| 403 | case "photoshop:State": |
---|
| 404 | case "photoshop:TransmissionReference": |
---|
[4931] | 405 | case "photoshop:ICCProfile": |
---|
[4686] | 406 | case "crs:AutoBrightness": |
---|
| 407 | case "crs:AutoContrast": |
---|
| 408 | case "crs:AutoExposure": |
---|
| 409 | case "crs:AutoShadows": |
---|
| 410 | case "crs:BlueHue": |
---|
| 411 | case "crs:BlueSaturation": |
---|
| 412 | case "crs:Brightness": |
---|
| 413 | case "crs:CameraProfile": |
---|
| 414 | case "crs:ChromaticAberrationB": |
---|
| 415 | case "crs:ChromaticAberrationR": |
---|
| 416 | case "crs:ColorNoiseReduction": |
---|
| 417 | case "crs:Contrast": |
---|
| 418 | case "crs:CropTop": |
---|
| 419 | case "crs:CropLeft": |
---|
| 420 | case "crs:CropBottom": |
---|
| 421 | case "crs:CropRight": |
---|
| 422 | case "crs:CropAngle": |
---|
| 423 | case "crs:CropWidth": |
---|
| 424 | case "crs:CropHeight": |
---|
| 425 | case "crs:Exposure": |
---|
| 426 | case "crs:GreenHue": |
---|
| 427 | case "crs:GreenSaturation": |
---|
| 428 | case "crs:HasCrop": |
---|
| 429 | case "crs:HasSettings": |
---|
| 430 | case "crs:LuminanceSmoothing": |
---|
| 431 | case "crs:RawFileName": |
---|
| 432 | case "crs:RedHue": |
---|
| 433 | case "crs:RedSaturation": |
---|
| 434 | case "crs:Saturation": |
---|
| 435 | case "crs:Shadows": |
---|
| 436 | case "crs:ShadowTint": |
---|
| 437 | case "crs:Sharpness": |
---|
| 438 | case "crs:Temperature": |
---|
| 439 | case "crs:Tint": |
---|
| 440 | case "crs:Version": |
---|
| 441 | case "crs:VignetteAmount": |
---|
| 442 | case "crs:VignetteMidpoint": |
---|
| 443 | case "Iptc4xmpCore:CountryCode": |
---|
| 444 | case "Iptc4xmpCore:Location": |
---|
| 445 | case "Iptc4xmpCore:CiEmailWork": |
---|
| 446 | case "Iptc4xmpCore:CiUrlWork": |
---|
| 447 | case "Iptc4xmpCore:CiTelWork": |
---|
| 448 | case "Iptc4xmpCore:CiAdrExtadr": |
---|
| 449 | case "Iptc4xmpCore:CiAdrPcode": |
---|
| 450 | case "Iptc4xmpCore:CiAdrCity": |
---|
| 451 | case "Iptc4xmpCore:CiAdrCtry": |
---|
| 452 | $returned=$value; |
---|
| 453 | break; |
---|
| 454 | case "Iptc4xmpCore:IntellectualGenre": |
---|
| 455 | $returned=explode(":", $value); |
---|
| 456 | break; |
---|
[5237] | 457 | case "exif:GPSLatitude": |
---|
| 458 | case "exif:GPSLongitude": |
---|
| 459 | case "exif:GPSDestLatitude": |
---|
| 460 | case "exif:GPSDestLongitude": |
---|
| 461 | $returned=Array('coord' => "", 'card'=>""); |
---|
| 462 | preg_match_all('/(\d{1,3}),(\d{1,2})(?:\.(\d*)){0,1}(N|S|E|W)/', $value, $result); |
---|
| 463 | $returned['coord']=$result[1][0]."° ".$result[2][0]."' "; |
---|
| 464 | if(trim($result[3][0])!="") |
---|
| 465 | { |
---|
| 466 | $returned['coord'].= round(("0.".$result[3][0])*60,2)."\""; |
---|
| 467 | } |
---|
| 468 | switch($result[4][0]) |
---|
| 469 | { |
---|
| 470 | case "N": |
---|
| 471 | $returned['card']="North"; |
---|
| 472 | break; |
---|
| 473 | case "S": |
---|
| 474 | $returned['card']="South"; |
---|
| 475 | break; |
---|
| 476 | case "E": |
---|
| 477 | $returned['card']="East"; |
---|
| 478 | break; |
---|
| 479 | case "W": |
---|
| 480 | $returned['card']="West"; |
---|
| 481 | break; |
---|
| 482 | } |
---|
| 483 | $type=ByteType::UNDEFINED; |
---|
| 484 | break; |
---|
[4686] | 485 | case "xmp:CreateDate": |
---|
| 486 | case "xmp:ModifyDate": |
---|
| 487 | case "xmp:MetadataDate": |
---|
| 488 | case "tiff:DateTime": |
---|
| 489 | case "photoshop:DateCreated": |
---|
| 490 | case "Iptc4xmpCore:DateCreated": |
---|
| 491 | $returned=ConvertData::toDateTime($value); |
---|
| 492 | break; |
---|
| 493 | case "dc:contributor" : // bag |
---|
| 494 | case "dc:creator" : // seq |
---|
| 495 | case "dc:date" : // seq |
---|
| 496 | case "dc:description" : // alt |
---|
| 497 | case "dc:language" : // bag |
---|
| 498 | case "dc:publisher" : // bag |
---|
| 499 | case "dc:relation" : // bag |
---|
| 500 | case "dc:rights" : // alt |
---|
| 501 | case "dc:subject" : // bag |
---|
| 502 | case "dc:title" : // alt |
---|
| 503 | case "dc:Type" : // bag |
---|
| 504 | case "xmp:Advisory" : // bag |
---|
| 505 | case "xmp:Identifier" : // bag |
---|
| 506 | case "xmp:Thumbnails" : // alt |
---|
| 507 | case "xmpRights:Owner" : // bag |
---|
| 508 | case "xmpRights:UsageTerms" : // alt |
---|
| 509 | case "xmpMM:History" : // seq |
---|
| 510 | case "xmpMM:Versions" : // seq |
---|
| 511 | case "xmpBJ:JobRef" : // bag |
---|
| 512 | case "xmpTPg:Fonts" : // bag |
---|
| 513 | case "xmpTPg:Colorants" : // seq |
---|
| 514 | case "xmpTPg:PlateNames" : // seq |
---|
| 515 | case "photoshop:SupplementalCategories" : // bag |
---|
| 516 | case "crs:ToneCurve" : // seq |
---|
| 517 | case "tiff:BitsPerSample" : // seq |
---|
| 518 | case "tiff:YCbCrSubSampling" : // seq |
---|
| 519 | case "tiff:TransferFunction" : // seq |
---|
| 520 | case "tiff:WhitePoint" : // seq |
---|
| 521 | case "tiff:PrimaryChromaticities" : // seq |
---|
| 522 | case "tiff:YCbCrCoefficients" : // seq |
---|
| 523 | case "tiff:ReferenceBlackWhite" : // seq |
---|
| 524 | case "tiff:ImageDescription" : // alt |
---|
| 525 | case "tiff:Copyright" : // alt |
---|
| 526 | case "exif:ComponentsConfiguration" : // seq |
---|
| 527 | case "exif:UserComment" : // alt |
---|
| 528 | case "exif:ISOSpeedRatings" : // seq |
---|
| 529 | case "exif:SubjectArea" : // seq |
---|
| 530 | case "exif:SubjectLocation" : // seq |
---|
[6889] | 531 | case "digiKam:TagsList": //seq |
---|
[7441] | 532 | case "lr:hierarchicalSubject": //seq |
---|
[4686] | 533 | $returned=$value; |
---|
| 534 | break; |
---|
| 535 | case "Iptc4xmpCore:Scene": //bag |
---|
| 536 | $tag=$this->tagDef->getTagById('Iptc4xmpCore:Scene'); |
---|
| 537 | $returned=$value; |
---|
| 538 | foreach($returned['values'] as $key=>$val) |
---|
| 539 | { |
---|
| 540 | if(array_key_exists($val, $tag['tagValues.special'])) |
---|
| 541 | $returned['values'][$key]=$tag['tagValues.special'][$val]; |
---|
| 542 | } |
---|
[4904] | 543 | unset($tag); |
---|
[4686] | 544 | break; |
---|
| 545 | case "Iptc4xmpCore:SubjectCode": //bag |
---|
| 546 | $returned=$value; |
---|
| 547 | foreach($returned['values'] as $key=>$val) |
---|
| 548 | { |
---|
| 549 | $tmp=explode(":", $val); |
---|
| 550 | |
---|
| 551 | $returned['values'][$key]=Array(); |
---|
| 552 | |
---|
| 553 | if(count($tmp)>=1) |
---|
| 554 | $returned['values'][$key]['IPR']=$tmp[0]; |
---|
| 555 | |
---|
| 556 | if(count($tmp)>=2) |
---|
| 557 | $returned['values'][$key]['subjectCode']=$tmp[1]; |
---|
| 558 | |
---|
| 559 | if(count($tmp)>=3) |
---|
| 560 | $returned['values'][$key]['subjectName']=$tmp[2]; |
---|
| 561 | |
---|
| 562 | if(count($tmp)>=4) |
---|
| 563 | $returned['values'][$key]['subjectMatterName']=$tmp[3]; |
---|
| 564 | |
---|
| 565 | if(count($tmp)>=5) |
---|
| 566 | $returned['values'][$key]['subjectDetailName']=$tmp[4]; |
---|
[4904] | 567 | |
---|
| 568 | unset($tmp); |
---|
[4686] | 569 | } |
---|
| 570 | break; |
---|
| 571 | default: |
---|
| 572 | $returned="Not yet implemented; $name"; |
---|
| 573 | break; |
---|
| 574 | } |
---|
| 575 | return($returned); |
---|
| 576 | } |
---|
| 577 | |
---|
| 578 | /** |
---|
| 579 | * this function convert the value from XMP 'exif' or XMP 'tiff' data by |
---|
| 580 | * using an instance of a XmpTag2Exif object (using exif tag object allows |
---|
| 581 | * not coding the same things twice) |
---|
| 582 | */ |
---|
| 583 | private function xmp2Exif($tagName, $exifTag, $xmpValue) |
---|
| 584 | { |
---|
| 585 | switch($tagName) |
---|
| 586 | { |
---|
| 587 | /* integers */ |
---|
| 588 | case "tiff:ImageWidth": |
---|
| 589 | case "tiff:ImageLength": |
---|
| 590 | case "tiff:PhotometricInterpretation": |
---|
| 591 | case "tiff:Orientation": |
---|
| 592 | case "tiff:SamplesPerPixel": |
---|
| 593 | case "tiff:PlanarConfiguration": |
---|
| 594 | case "tiff:YCbCrSubSampling": |
---|
| 595 | case "tiff:YCbCrPositioning": |
---|
| 596 | case "tiff:ResolutionUnit": |
---|
| 597 | case "exif:ColorSpace": |
---|
| 598 | case "exif:PixelXDimension": |
---|
| 599 | case "exif:PixelYDimension": |
---|
| 600 | case "exif:MeteringMode": |
---|
| 601 | case "exif:LightSource": |
---|
| 602 | case "exif:FlashEnergy": |
---|
| 603 | case "exif:FocalPlaneResolutionUnit": |
---|
| 604 | case "exif:SensingMethod": |
---|
| 605 | case "exif:FileSource": |
---|
| 606 | case "exif:SceneType": |
---|
| 607 | case "exif:CustomRendered": |
---|
| 608 | case "exif:ExposureMode": |
---|
| 609 | case "exif:Balance": |
---|
| 610 | case "exif:FocalLengthIn35mmFilm": |
---|
| 611 | case "exif:SceneCaptureType": |
---|
| 612 | case "exif:GainControl": |
---|
| 613 | case "exif:Contrast": |
---|
| 614 | case "exif:Saturation": |
---|
| 615 | case "exif:Sharpness": |
---|
| 616 | case "exif:SubjectDistanceRange": |
---|
| 617 | case "exif:GPSAltitudeRef": |
---|
| 618 | case "exif:GPSDifferential": |
---|
| 619 | $returned=(int)$xmpValue; |
---|
| 620 | $type=ByteType::ULONG; |
---|
| 621 | break; |
---|
| 622 | /* specials */ |
---|
| 623 | case "tiff:BitsPerSample": |
---|
| 624 | case "tiff:Compression": |
---|
| 625 | case "tiff:TransferFunction": |
---|
| 626 | case "tiff:WhitePoint": |
---|
| 627 | case "tiff:PrimaryChromaticities": |
---|
| 628 | case "tiff:YCbCrCoefficients": |
---|
| 629 | case "tiff:ReferenceBlackWhite": |
---|
| 630 | case "exif:ComponentsConfiguration": |
---|
| 631 | case "exif:ExposureProgram": |
---|
| 632 | case "exif:ISOSpeedRatings": |
---|
| 633 | case "exif:OECF": |
---|
| 634 | case "exif:Flash": |
---|
| 635 | case "exif:SubjectArea": |
---|
| 636 | case "exif:SpatialFrequencyResponse": |
---|
| 637 | case "exif:SubjectLocation": |
---|
| 638 | case "exif:CFAPattern": |
---|
| 639 | case "exif:DeviceSettingDescription": |
---|
| 640 | $returned=$xmpValue; |
---|
| 641 | $type=ByteType::UNDEFINED; |
---|
| 642 | break; |
---|
| 643 | /* rational */ |
---|
| 644 | case "tiff:XResolution": |
---|
| 645 | case "tiff:YResolution": |
---|
| 646 | case "exif:CompressedBitsPerPixel": |
---|
| 647 | case "exif:ExposureTime": |
---|
| 648 | case "exif:FNumber": |
---|
| 649 | case "exif:ShutterSpeedValue": |
---|
| 650 | case "exif:ApertureValue": |
---|
| 651 | case "exif:BrightnessValue": |
---|
| 652 | case "exif:ExposureBiasValue": |
---|
| 653 | case "exif:MaxApertureValue": |
---|
| 654 | case "exif:SubjectDistance": |
---|
| 655 | case "exif:FocalLength": |
---|
| 656 | case "exif:FocalPlaneXResolution": |
---|
| 657 | case "exif:FocalPlaneYResolution": |
---|
| 658 | case "exif:ExposureIndex": |
---|
| 659 | case "exif:DigitalZoomRatio": |
---|
| 660 | case "exif:GPSAltitude": |
---|
| 661 | case "exif:GPSDOP": |
---|
| 662 | case "exif:GPSSpeed": |
---|
| 663 | case "exif:GPSTrack": |
---|
| 664 | case "exif:GPSImgDirection": |
---|
| 665 | case "exif:GPSDestBearing": |
---|
| 666 | case "exif:GPSDestDistance": |
---|
| 667 | $computed=explode("/", $xmpValue); |
---|
| 668 | $returned=Array((int)$computed[0], (int)$computed[1]); |
---|
| 669 | $type=ByteType::URATIONAL; |
---|
[4904] | 670 | unset($computed); |
---|
[4686] | 671 | break; |
---|
| 672 | /* dates & texts */ |
---|
| 673 | case "tiff:DateTime": |
---|
| 674 | case "tiff:ImageDescription": |
---|
| 675 | case "tiff:Make": |
---|
| 676 | case "tiff:Model": |
---|
| 677 | case "tiff:Software": |
---|
| 678 | case "tiff:Artist": |
---|
| 679 | case "tiff:Copyright": |
---|
| 680 | case "exif:ExifVersion": |
---|
| 681 | case "exif:FlashpixVersion": |
---|
| 682 | case "exif:UserComment": |
---|
| 683 | case "exif:RelatedSoundFile": |
---|
| 684 | case "exif:DateTimeOriginal": |
---|
| 685 | case "exif:DateTimeDigitized": |
---|
| 686 | case "exif:SpectralSensitivity": |
---|
| 687 | case "exif:ImageUniqueID": |
---|
| 688 | case "exif:GPSVersionID": |
---|
| 689 | case "exif:GPSTimeStamp": |
---|
| 690 | case "exif:GPSSatellites": |
---|
| 691 | case "exif:GPSStatus": |
---|
| 692 | case "exif:GPSMeasureMode": |
---|
| 693 | case "exif:GPSSpeedRef": |
---|
| 694 | case "exif:GPSTrackRef": |
---|
| 695 | case "exif:GPSImgDirectionRef": |
---|
| 696 | case "exif:GPSMapDatum": |
---|
| 697 | case "exif:GPSDestBearingRef": |
---|
| 698 | case "exif:GPSDestDistanceRef": |
---|
| 699 | case "exif:GPSProcessingMethod": |
---|
| 700 | case "exif:GPSAreaInformation": |
---|
| 701 | $returned=$xmpValue; |
---|
| 702 | $type=ByteType::ASCII; |
---|
| 703 | break; |
---|
| 704 | default: |
---|
| 705 | $returned="Unknown tag: $tagName => $xmpValue"; |
---|
| 706 | break; |
---|
| 707 | } |
---|
| 708 | if(is_array($returned)) |
---|
| 709 | { |
---|
| 710 | if(array_key_exists('type', $returned)) |
---|
| 711 | { |
---|
| 712 | if($returned['type']=='alt') |
---|
| 713 | { |
---|
| 714 | } |
---|
| 715 | else |
---|
| 716 | { |
---|
| 717 | foreach($returned['values'] as $key => $val) |
---|
| 718 | { |
---|
| 719 | $returned['values'][$key]['value']=$this->xmpTag2Exif->convert($exifTag, $val['value'], $type); |
---|
| 720 | } |
---|
| 721 | } |
---|
| 722 | } |
---|
| 723 | else |
---|
| 724 | { |
---|
| 725 | return($this->xmpTag2Exif->convert($exifTag, $returned, $type)); |
---|
| 726 | } |
---|
| 727 | } |
---|
| 728 | return($returned); |
---|
| 729 | } |
---|
| 730 | |
---|
| 731 | } |
---|
| 732 | |
---|
| 733 | /** |
---|
| 734 | * The XmpTag2Exif is derived from the IfdReader class |
---|
| 735 | * |
---|
| 736 | * This function provides the public function 'convert', allowing to convert |
---|
| 737 | * 'exif' datas in 'human readable' values |
---|
| 738 | * |
---|
| 739 | */ |
---|
| 740 | class XmpTag2Exif extends IfdReader |
---|
| 741 | { |
---|
| 742 | public function convert($exifTag, $value, $type) |
---|
| 743 | { |
---|
| 744 | return($this->processSpecialTag($exifTag, $value, $type)); |
---|
| 745 | } |
---|
| 746 | } |
---|
| 747 | |
---|
| 748 | ?> |
---|