Changeset 538


Ignore:
Timestamp:
Sep 27, 2004, 11:51:07 PM (20 years ago)
Author:
z0rglub
Message:

add support of exif and iptc for remote site

Location:
trunk/admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/create_listing_file.php

    r526 r538  
    3838                          'avi','mp3','ogg');
    3939
    40 // $conf['picture_ext'] must bea subset of $conf['file_ext']
     40// $conf['picture_ext'] must be a subset of $conf['file_ext']
    4141$conf['picture_ext'] = array('jpg','JPG','png','PNG','gif','GIF');
    4242
     
    4545$conf['version'] = 'BSF';
    4646
     47// $conf['use_exif'] set to true if you want to use Exif Date as "creation
     48// date" for the element, otherwise, set to false
     49$conf['use_exif'] = true;
     50
     51// $conf['use_iptc'] set to true if you want to use IPTC informations of the
     52// element according to get_sync_iptc_data function mapping, otherwise, set
     53// to false
     54$conf['use_iptc'] = false;
     55
    4756// +-----------------------------------------------------------------------+
    4857// |                               functions                               |
    4958// +-----------------------------------------------------------------------+
     59
     60/**
     61 * returns informations from IPTC metadata, mapping is done at the beginning
     62 * of the function
     63 *
     64 * @param string $filename
     65 * @return array
     66 */
     67function get_iptc_data($filename, $map)
     68{
     69  $result = array();
     70 
     71  // Read IPTC data
     72  $iptc = array();
     73 
     74  $imginfo = array();
     75  getimagesize($filename, $imginfo);
     76 
     77  if (isset($imginfo['APP13']))
     78  {
     79    $iptc = iptcparse($imginfo['APP13']);
     80    if (is_array($iptc))
     81    {
     82      $rmap = array_flip($map);
     83      foreach (array_keys($rmap) as $iptc_key)
     84      {
     85        if (isset($iptc[$iptc_key][0]) and $value = $iptc[$iptc_key][0])
     86        {
     87          // strip leading zeros (weird Kodak Scanner software)
     88          while ($value[0] == chr(0))
     89          {
     90            $value = substr($value, 1);
     91          }
     92          // remove binary nulls
     93          $value = str_replace(chr(0x00), ' ', $value);
     94         
     95          foreach (array_keys($map, $iptc_key) as $pwg_key)
     96          {
     97            $result[$pwg_key] = $value;
     98          }
     99        }
     100      }
     101    }
     102  }
     103  return $result;
     104}
     105
     106function get_sync_iptc_data($file)
     107{
     108  $map = array(
     109    'keywords'        => '2#025',
     110    'date_creation'   => '2#055',
     111    'author'          => '2#122',
     112    'name'            => '2#085',
     113    'comment'         => '2#120'
     114    );
     115  $datefields = array('date_creation', 'date_available');
     116 
     117  $iptc = get_iptc_data($file, $map);
     118
     119  foreach ($iptc as $pwg_key => $value)
     120  {
     121    if (in_array($pwg_key, $datefields))
     122    {
     123      if ( preg_match('/(\d{4})(\d{2})(\d{2})/', $value, $matches))
     124      {
     125        $iptc[$pwg_key] = $matches[1].'-'.$matches[2].'-'.$matches[3];
     126      }
     127    }
     128  }
     129
     130  return $iptc;
     131}
    50132
    51133/**
     
    265347          $element['height'] = $image_size[1];
    266348        }
     349
     350        if ($conf['use_exif'])
     351        {
     352          if ($exif = @read_exif_data($dir.'/'.$fs_file))
     353          {
     354            if (isset($exif['DateTime']))
     355            {
     356              preg_match('/^(\d{4}):(\d{2}):(\d{2})/'
     357                         ,$exif['DateTime']
     358                         ,$matches);
     359              $element['date_creation'] =
     360                $matches[1].'-'.$matches[2].'-'.$matches[3];
     361            }
     362          }
     363        }
     364
     365        if ($conf['use_iptc'])
     366        {
     367          $iptc = get_sync_iptc_data($dir.'/'.$fs_file);
     368          if (count($iptc) > 0)
     369          {
     370            foreach (array_keys($iptc) as $key)
     371            {
     372              $element[$key] = addslashes($iptc[$key]);
     373            }
     374          }
     375        }
    267376       
    268377        array_push($elements, $element);
     
    300409  $xml = "\n".$indent.'<root>';
    301410  $attributes = array('file','tn_ext','representative_ext','filesize',
    302                       'width','height');
     411                      'width','height','date_creation','author','keywords',
     412                      'name','comment');
    303413  foreach ($elements as $element)
    304414  {
  • trunk/admin/remote_site.php

    r534 r538  
    414414                             'filesize',
    415415                             'width',
    416                              'height');
     416                             'height',
     417                             'date_creation',
     418                             'author',
     419                             'keywords',
     420                             'name',
     421                             'comment');
    417422      foreach ($optional_atts as $att)
    418423      {
     
    429434  {
    430435    $dbfields = array('file','storage_category_id','date_available','tn_ext',
    431                       'filesize','width','height');
     436                      'filesize','width','height','date_creation','author',
     437                      'keywords','name','comment');
    432438    mass_inserts(IMAGES_TABLE, $dbfields, $inserts);
    433439    $counts{'new_elements'}+= count($inserts);
Note: See TracChangeset for help on using the changeset viewer.