Changeset 4998


Ignore:
Timestamp:
Feb 28, 2010, 6:15:11 PM (14 years ago)
Author:
grum
Message:

Small bugs fixed + implementation of "Magic" metadata

Location:
extensions/AMetaData/JpegMetaData
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • extensions/AMetaData/JpegMetaData/JpegMetaData.class.php

    r4935 r4998  
    113113
    114114  require_once(JPEG_METADATA_DIR."Readers/JpegReader.class.php");
     115  require_once(JPEG_METADATA_DIR."TagDefinitions/MagicTags.class.php");
    115116
    116117  class JpegMetaData
     
    123124    const KEY_EXIF_EXIF = "exif.exif";
    124125    const KEY_EXIF_GPS  = "exif.gps";
    125     const KEY_EXIF = "exif";
    126     const KEY_IPTC = "iptc";
    127     const KEY_XMP  = "xmp";
     126    const KEY_EXIF  = "exif";
     127    const KEY_IPTC  = "iptc";
     128    const KEY_XMP   = "xmp";
     129    const KEY_MAGIC = "magic";
    128130
    129131    private $jpeg = null;
     
    157159     * xmp                  |
    158160     * maker                | maker => returns specifics tags from all the known
    159      *                      |          makers
     161     * magic                |          makers
    160162     *                      |
    161163     * ---------------------+---------------------------------------------------
     
    180182        'iptc'  => true,
    181183        'xmp'   => true,
    182         'maker' => true
     184        'maker' => true,
     185        'magic' => true,
    183186      );
    184187
     
    211214        $list[]="xmp";
    212215
     216      if($default['magic'])
     217        $list[]="magic";
     218
    213219      foreach($list as $val)
    214220      {
     
    232238            $tmp=new XmpTags();
    233239            $schema="xmp";
     240            break;
     241          case "magic":
     242            $tmp=new MagicTags();
     243            $schema="magic";
    234244            break;
    235245          case MAKER_PENTAX:
     
    281291          }
    282292      }
     293
     294      ksort($returned);
    283295
    284296      return($returned);
     
    332344     * iptc                 | If set to true, the function returns all the tags
    333345     * xmp                  | known for the specified type tag
    334      *                      | the exif parameter include the maker tags
     346     * magic                | the exif parameter include the maker tags
    335347     *                      |
    336348     * ---------------------+---------------------------------------------------
     
    404416          }
    405417        }
     418
     419        if($this->options['magic'])
     420        {
     421          $this->processMagicTags();
     422        }
     423
     424        ksort($this->tags);
    406425      }
    407426    }
     
    468487        'filter' => self::TAGFILTER_ALL,
    469488        'optimizeIptcDateTime' => false,
    470         'exif' => true,
    471         'iptc' => true,
    472         'xmp'  => true
     489        'exif'  => true,
     490        'iptc'  => true,
     491        'xmp'   => true,
     492        'magic' => true
    473493      );
    474494
     
    552572    }
    553573
     574    /**
     575     * MagicTags are build with this function
     576     */
     577    private function processMagicTags()
     578    {
     579      $magicTags=new MagicTags();
     580
     581      foreach($magicTags->getTags() as $key => $val)
     582      {
     583        $tag=new Tag($key,0,$key);
     584
     585        for($i=0; $i<count($val['tagValues']); $i++)
     586        {
     587          $found=true;
     588          preg_match_all('/{([a-z0-9:\.\s\/]*)(\[.*\])?}/i', $val['tagValues'][$i], $returned, PREG_PATTERN_ORDER);
     589          foreach($returned[1] as $testKey)
     590          {
     591            $found=$found & array_key_exists($testKey, $this->tags);
     592          }
     593          if(count($returned[1])==0) $found=false;
     594
     595          if($found)
     596          {
     597            $returned=trim(preg_replace_callback(
     598                '/{([a-z0-9:\.\s\/\[\]]*)}/i',
     599                Array(&$this, "processMagicTagsCB"),
     600                $val['tagValues'][$i]
     601            ));
     602
     603            $tag->setValue($returned);
     604            $tag->setLabel($returned);
     605            $tag->setKnown(true);
     606            $tag->setImplemented($val['implemented']);
     607            $tag->setTranslatable($val['translatable']);
     608
     609            $i=count($val['tagValues']);
     610          }
     611        }
     612
     613        if($tag->isImplemented() and $found)
     614        {
     615          $this->tags["magic.".$key]=$tag;
     616        }
     617
     618        unset($tag);
     619      }
     620      unset($magicTags);
     621    }
     622
     623    /**
     624     * this function is called by the processMagicTags to replace tagId by the
     625     * tag values
     626     *
     627     * @param Array $matches : array[1] = the tagId
     628     * @return String : the tag value
     629     */
     630    private function processMagicTagsCB($matches)
     631    {
     632      $label="";
     633      preg_match_all('/([a-z0-9:\.\s\/]*)\[(.*)\]/i', $matches[1], $result, PREG_PATTERN_ORDER);
     634      if(count($result[0])>0)
     635      {
     636
     637        if(array_key_exists($result[1][0], $this->tags))
     638        {
     639          $tag=$this->tags[$result[1][0]]->getLabel();
     640
     641          preg_match_all('/([a-z0-9:\.\s\/]*)\[(.*)\]/i', $result[2][0], $result2, PREG_PATTERN_ORDER);
     642
     643          if(count($result2[0])>0)
     644          {
     645            if(array_key_exists($result2[2][0], $tag[$result2[1][0]] ))
     646              $label=$tag[$result2[1][0]][$result2[2][0]];
     647          }
     648          else
     649          {
     650            if(array_key_exists($result[2][0], $tag))
     651              $label=$tag[$result[2][0]];
     652          }
     653        }
     654      }
     655      else
     656      {
     657        if(array_key_exists($matches[1], $this->tags))
     658        {
     659          $label=$this->tags[$matches[1]]->getLabel();
     660        }
     661      }
     662
     663      if($label instanceof DateTime)
     664        return($label->format("Y-m-d H:i:s"));
     665
     666      $label=XmpTags::getAltValue($label, L10n::getLanguage());
     667
     668      if(is_array($label))
     669        return(implode(", ", $label));
     670
     671      return(trim($label));
     672    }
     673
     674
     675
     676    /**
     677     * used by the destructor to clean variables
     678     */
    554679    private function unsetAll()
    555680    {
  • extensions/AMetaData/JpegMetaData/Readers/IfdReader.class.php

    r4904 r4998  
    496496          $returned=Array(
    497497            "computed" => (isset($tag['tagValues.computed'][$values])?$tag['tagValues.computed'][$values]:"unknown"),
    498             "detail" => Array() );
    499           foreach($tag['tagValues.specialNames'] as $key => $value)
    500           {
    501             $filter = $values & $key;
    502             if(isset($tag['tagValues.specialValues'][$key][$filter]))
    503               $returned["detail"][]=$tag['tagValues.specialValues'][$key][$filter];
    504             else
    505               $returned["detail"][]="unknown";
    506           }
     498            "detail" => Array()
     499          );
     500
     501          $value=$values & 0x0001;
     502          $returned["detail"][]=$tag['tagValues.specialValues'][0x0001][$value];
     503
     504          $value=($values & 0x0006)>>1;
     505          $returned["detail"][]=$tag['tagValues.specialValues'][0x0006][$value];
     506
     507          $value=($values & 0x0018)>>3;
     508          $returned["detail"][]=$tag['tagValues.specialValues'][0x0018][$value];
     509
     510          $value=($values & 0x0020)>>5;
     511          $returned["detail"][]=$tag['tagValues.specialValues'][0x0020][$value];
     512
     513          $value=($values & 0x0040)>>6;
     514          $returned["detail"][]=$tag['tagValues.specialValues'][0x0040][$value];
     515
    507516          break;
    508517        case 0x920A: // FocalLength, tag 0x920A
  • extensions/AMetaData/JpegMetaData/Readers/PentaxReader.class.php

    r4931 r4998  
    148148        case 0x000c: // "Flash",
    149149          $tag=$this->tagDef->getTagById(0x000c);
    150           $returned="";
     150          $returned=Array();
    151151          if(array_key_exists($values[0], $tag['tagValues.special'][0]))
    152             $returned.=$tag['tagValues.special'][0][$values[0]];
     152            $returned[]=$tag['tagValues.special'][0][$values[0]];
    153153          if(array_key_exists($values[1], $tag['tagValues.special'][1]))
    154             $returned.=";".$tag['tagValues.special'][1][$values[1]];
     154            $returned[]=";".$tag['tagValues.special'][1][$values[1]];
    155155          unset($tag);
    156156          break;
  • extensions/AMetaData/JpegMetaData/TagDefinitions/IfdTags.class.php

    r4935 r4998  
    977977      // flash, tag 0x9209, see EXIF 2.2 documentation
    978978      0x9209 => Array(
    979         'tagName'     => "flash",
     979        'tagName'     => "Flash",
    980980        'schema'      => "exif",
    981981        'translatable'=> true,
     
    990990                ),
    991991        'tagValues.specialValues' => Array(
    992           0x0000 => Array( // b00000001
     992          0x0001 => Array( // b00000001 => 'fired'
    993993                  0x00 => "flash did not fire",
    994994                  0x01 => "flash fired"
    995995                ),
    996           0x0006 => Array( // b00000110
     996          0x0006 => Array( // b00000110 => 'return'
    997997                  0x00 => "no strobe",                        // 00
    998998                  0x01 => "reserved",                         // 01
     
    10001000                  0x03 => "strobe return light detected"      // 11
    10011001                ),
    1002           0x0018 => Array( // b00011000
     1002          0x0018 => Array( // b00011000 => 'mode'
    10031003                  0x00 => "unknown",
    10041004                  0x01 => "compulsory flash firing",
    1005                   0x10 => "compulsory flash suppression",
    1006                   0x11 => "auto mode"
     1005                  0x02 => "compulsory flash suppression",
     1006                  0x03 => "auto mode"
    10071007                ),
    1008           0x0020 => Array( // b00100000
     1008          0x0020 => Array( // b00100000 => 'function'
    10091009                  0x00 => "flash function present",
    10101010                  0x01 => "no flash function"
    10111011                ),
    1012           0x0040 => Array( // b01000000
     1012          0x0040 => Array( // b01000000 => 'red-eye'
    10131013                  0x00 => "no red-eye reduction mode or unknown",
    10141014                  0x01 => "red-eye reduction supported"
  • extensions/AMetaData/JpegMetaData/TagDefinitions/XmpTags.class.php

    r4972 r4998  
    4848  class XmpTags extends KnownTags
    4949  {
     50    /**
     51     * this function extract from an Xmp Alt structure, the value in the given
     52     * lang
     53     *
     54     * @param Array $tagValues :
     55     * @param String $lang : the needed lang
     56     * @return String : the value in the specified lang, or in the default lang
     57     *                  if there is no specific value for the specified lang
     58     */
     59    static public function getAltValue($tagValues, $lang="x-default")
     60    {
     61      /*
     62       * test if the $tagValues is valid, otherwise return the $tagValues as
     63       * result
     64       */
     65      if(!is_array($tagValues)) return($tagValues);
     66      if(!array_key_exists("type", $tagValues) or
     67         !array_key_exists("values", $tagValues) )
     68         return($tagValues);
     69      if($tagValues['type']!="alt") return($tagValues);
     70
     71      $returned="";
     72      foreach($tagValues['values'] as $key => $val)
     73      {
     74        if($val['type']['value']==$lang or
     75           XmpTags::lang($val['type']['value'])==$lang or
     76           $val['type']['value']=="x-default")
     77          $returned=$val['value'];
     78      }
     79      return($returned);
     80    }
     81
     82    /**
     83     * this function tries to format the lang Id
     84     * something like "fr-fr" is returned as "fr_FR"
     85     */
     86    static private function lang($lang)
     87    {
     88      $result=preg_match("/([a-z]*)([-|_])([a-z]*)/i", $lang, $arr);
     89      return($arr[1]."_".strtoupper($arr[3]));
     90    }
     91
    5092    const TYPE_SIMPLE = 0x00;
    5193    const TYPE_SEQ = 0x01;
     
    13081350/*
    13091351 * The Flash is a sequence of Flash structure
    1310  * Not yet implemented
     1352 * Don't use the exif:Flash, but the associated tags :
     1353 *  exif:Fired, exif:Return, exif:Mode, exif:Function, exif:RedEyeMode
    13111354 */
    13121355      'exif:Flash' => Array(
     
    13171360        'schema'       => "exif",
    13181361      ),
     1362
     1363      'exif:Fired' => Array(
     1364        'implemented'  => true,
     1365        'translatable' => true,
     1366        'type'         => self::TYPE_SIMPLE,
     1367        'schema'       => "exif",
     1368        'tagValues' => Array(
     1369            'False' => "flash did not fire",
     1370            'True'  => "flash fired"
     1371        ),
     1372      ),
     1373
     1374      'exif:Return' => Array(
     1375        'implemented'  => true,
     1376        'translatable' => true,
     1377        'type'         => self::TYPE_SIMPLE,
     1378        'schema'       => "exif",
     1379        'tagValues' => Array(
     1380            0x00 => "no strobe",
     1381            0x01 => "reserved",
     1382            0x02 => "strobe return light not detected",
     1383            0x03 => "strobe return light detected"
     1384        ),
     1385      ),
     1386
     1387      'exif:Mode' => Array(
     1388        'implemented'  => true,
     1389        'translatable' => true,
     1390        'type'         => self::TYPE_SIMPLE,
     1391        'schema'       => "exif",
     1392        'tagValues' => Array(
     1393            0x00 => "unknown",
     1394            0x01 => "compulsory flash firing",
     1395            0x02 => "compulsory flash suppression",
     1396            0x03 => "auto mode"
     1397        ),
     1398      ),
     1399
     1400      'exif:Function' => Array(
     1401        'implemented'  => true,
     1402        'translatable' => true,
     1403        'type'         => self::TYPE_SIMPLE,
     1404        'schema'       => "exif",
     1405        'tagValues' => Array(
     1406            'False' => "flash function present",
     1407            'True'  => "no flash function"
     1408        ),
     1409      ),
     1410
     1411      'exif:RedEyeMode' => Array(
     1412        'implemented'  => true,
     1413        'translatable' => true,
     1414        'type'         => self::TYPE_SIMPLE,
     1415        'schema'       => "exif",
     1416        'tagValues' => Array(
     1417            'False' => "no red-eye reduction mode or unknown",
     1418            'True'  => "red-eye reduction supported"
     1419          ),
     1420      ),
     1421
    13191422      'exif:FocalLength' => Array(
    13201423        'exifTag'      => 0x920A,
Note: See TracChangeset for help on using the changeset viewer.