source: extensions/MoreExif_EOS300D-40D/picture_metadata.inc.php @ 7690

Last change on this file since 7690 was 4667, checked in by Gotcha, 14 years ago

[extension] MoreExif - Point zero

File size: 19.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24/**
25 * This file is included by the picture page to manage picture metadata
26 *
27  Release 2.0.1 fix translation with common.lang.php definition
28  Release 2.0.2   manage 50D
29  Release 2.0.3/4 default 35mm focal length calculation for most common cameras / DSLR
30  All cameras will take benefit from this file, but the Canon at most.
31  If you have a non Canon body and would like to see the MakerNotes, follow the metadata information, e.g. from
32  http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/ and enhance this file!
33 */
34include_once(PHPWG_ROOT_PATH.'/include/functions_metadata.inc.php');
35if (($conf['show_exif']) and (function_exists('read_exif_data')))
36{
37  if ($exif = @read_exif_data($picture['current']['image_path']))
38  {
39    $exif = trigger_event('format_exif_data', $exif, $picture['current'] );
40 
41    $tpl_meta = array(
42        'TITLE' => 'EXIF Metadata',
43        'lines' => array(),
44      );
45
46    // register make and model
47    if (in_array('Make', $exif))   
48        { $make = trim($exif['Make']); }
49    else 
50        { $make = 'n/a'; }
51    if (in_array('Model', $exif)) 
52        { $model = trim($exif['Model']); }
53    else 
54        { $model ='n/a'; }
55       
56    foreach ($conf['show_exif_fields'] as $field)
57    {
58      if (strpos($field, ';') === false)
59      {  /*  ===> gbo modification  */
60        if (isset($exif[$field])) 
61        {
62           // Look for Canon EOS camera
63           if ($field == 'ModeArray') // Canon CameraSettings tags
64           {
65                if ($make === 'Canon') // for Canon EOS and PowerShot/Ixus
66                { improve_meta_canon($exif[$field]); }
67           }
68           else
69           {           
70                $key = $field; 
71                Conversion($key, $exif[$field], $model, $make);
72                if (isset($lang['exif_field_'.$field]))
73                {
74                        $key = $lang['exif_field_'.$field];
75                }               
76           }
77        // $tpl_meta['lines'][$key] = $exif[$field];
78        }
79      }
80      else
81      {
82        $tokens = explode(';', $field);
83        if (isset($exif[$tokens[0]][$tokens[1]]))
84        {
85           $key = $tokens[1];
86           if (isset($lang['exif_field_'.$tokens[1]]))
87           {
88              $key = $lang['exif_field_'.$tokens[1]];
89           }
90           $tpl_meta['lines'][$key] = $exif[$tokens[0]][$tokens[1]];
91        }
92      }
93    }
94    $template->append('metadata', $tpl_meta);
95  }
96}
97
98if ($conf['show_iptc'])
99{
100  $iptc = get_iptc_data($picture['current']['image_path'],
101                        $conf['show_iptc_mapping']);
102
103  if (count($iptc) > 0)
104  {
105    $tpl_meta = array(
106        'TITLE' => 'IPTC Metadata',
107        'lines' => array(),
108      );
109
110    foreach ($iptc as $field => $value)
111    {
112      $key = $field;
113      if (isset($lang[$field]))
114      {
115        $key = $lang[$field];
116      }
117      $tpl_meta['lines'][$key] = $value;
118    }
119    $template->append('metadata', $tpl_meta);
120  }
121}
122
123
124
125function Conversion($key, $data, $model, $make)
126{ 
127        global $tpl_meta, $lang;
128        // simplify make
129        $makeLow = strtolower($make); $makeR = $make;
130        if (strpos($makeLow, 'olympus') === 0 )
131        {       $makeR = 'Olympus'; }
132        else if (strpos($makeLow, 'nikon') === 0 )
133        {       $makeR = 'Nikon'; }
134        else if (strpos($makeLow, 'pentax') === 0 )
135        {       $makeR = 'Pentax'; }
136        else if (strpos($makeLow, 'sony') === 0 )
137        { 
138                $makeR = 'Sony'; 
139        }
140
141        // proceed and rename key to have user readable english name. The lang file should transalate these new keys.
142        if ($key==='Model')
143        {       // merge make and model if model does not already contain make
144                //if ($make <> 'Canon' && $makeR <> 'Pentax')
145                if (strpos( strtolower($model),  strtolower($makeR)) === false )
146                {   $data = $makeR.' '.$data; }         
147        }
148        if ($key==='ExposureBiasValue') 
149        {       
150                $key = 'ExposureCompensation';
151                $data = compute_fraction($data) ;
152                $data = round($data,2);
153                if ($data>0) {$data='+'.$data;} 
154                if ($data == 0) { $data = ""; }
155                else { $data.=' EV'; }
156        }               
157        if ($key==='ExposureTime') 
158        {
159                $key = 'ExposureTime';
160                $data = compute_fraction($data) ;
161                if ($data<1)   
162                {
163                        $data=1/$data;
164                        $data="1/".$data ; 
165                }
166                $data.="s";
167        }   
168        if ($key==='ShutterSpeedValue')
169        {
170                $key = 'ShutterSpeed';
171        }
172        if ($key=='FNumber') 
173        {       
174                $key = 'Aperture';
175                $data = compute_fraction($data) ;
176                $data = 'f/'. $data;
177        }
178        if ($key=="MaxApertureValue") 
179        {       
180                $key = 'MaxAperture';
181                $data = compute_fraction($data) ;
182                $data = round($data,1);
183                $data = 'f/'. $data;
184        }
185        if ($key==='FocalLength')
186        {       
187                $key = 'FocalLength';
188                $data = compute_fraction($data) ;
189                $data .='mm';   
190                // first look for 35mm eq in meta, else make the calculation
191                if (isset($exif['FocalLengthIn35mmFilm'])) 
192                {
193                        $f35 = compute_fraction($exif['FocalLengthIn35mmFilm']) ;
194                } 
195                else 
196                {
197                        $cropFactor = CalculateCropFactor($model, $makeR);
198                        if ($cropFactor > 1)
199                        { $f35 = $data*$cropFactor; }
200                }
201                if (isset($f35)) 
202                {
203                        $data.=' (equiv 24x36: '.round($f35,0).'mm)';
204                }
205        }
206
207
208        if ($key==='Flash')
209        { 
210                if ($make === 'Canon') 
211                { // disable it for Canon, as maker notes will be used
212                        $data="";
213                }
214                else
215                {  // it seems that most camera are using a even value for "not fired" and an odd value for "fired"
216                        if ($data%2 == 0)
217                        {  $data=""; } //did not fire
218                        else
219                        {  $data="on"; } // 1 on olympus camera, 9 or 25 on panasonic
220                }
221        }
222        if ($key==='UndefinedTag:0x0095' and $make === 'Canon')
223        {
224                $key = 'LensName';
225        }
226        if ($key==='ISOSpeedRatings')
227        {
228                $key = 'ISO';
229        }
230        if ($key==='DateTimeOriginal')
231        {
232                $key = 'TakenDate';
233        }       
234        if ($data!="" ) 
235        {
236                if (isset($lang['exif_field_'.$key]))
237                  { $key = $lang['exif_field_'.$key]; }
238                $tpl_meta['lines'][$key] = $data;
239        }
240}
241
242function compute_fraction($data)
243{ 
244        $tokens = explode('/', $data);
245        if (count($tokens)!=2) return $data ;
246        if ( $tokens[1] == 0 ) return $data ;
247        return floatval($tokens[0]) / floatval($tokens[1]) ;
248}
249
250// Calculate the crop factor of the camera which will be used for the 35mm focal length equivalence
251function CalculateCropFactor($model, $make)
252{
253        // set the crop factor
254        $cropFactor = 6; // average crop factor for compact cameras, for 1/2.5" sensor
255        if (strpos($model, 'Canon EOS') !== false) // only Canon EOS cameras
256        {
257                if (strpos($model, '0') > 0) // all APS-C models have a 0 in their name (Dx0, x0D, xx0D, x000D)
258                { $cropFactor = 1.6; }
259                else if (strpos($model, '1D ') > 0)  //1D body
260                { $cropFactor = 1.3; }
261                else { $cropFactor = 1; }  //1Ds and 5D body
262        }
263        else if ($make === 'Nikon' && strpos($model, 'D') !== false ) // all Nikon DSLR start with "D"
264        {
265                if (strpos($model, 'D3') !== false || strpos($model, 'D700') !== false)
266                {       $cropFactor = 1; }
267                else {  $cropFactor = 1.5; }
268        }
269        else if ($make === 'Sony'  && strpos($model, 'DSLR-A') !== false) // DSLR Alpha
270        {
271                if (strpos($model, 'A900') !== false)
272                {       $cropFactor = 1; }
273                else {  $cropFactor = 1.5; }
274        }
275        else if ($make === 'Pentax' && strpos($model, 'K') !== false ) // all Pentax DSLR start with "K"
276        {       $cropFactor = 1.5;  }
277        else if ($make === 'Olympus') // all Olympus DSLR start with "E"
278        {
279                if  (strpos($model, 'E') === 0)
280                {
281                    if (strpos($model, 'E-10') !== false || strpos($model, 'E-20') !== false)
282                    {   $cropFactor = 3.88;  }   // sensor size: 8.8x6.6, 2/3"
283                    else 
284                    {   $cropFactor = 2;  }   // sensor size: 18x13.5mm
285                }
286                else if ($model === 'C2040Z') // Eric's old compact camera
287                {       $cropFactor = 5.48;  } // sensor size: 1/2"
288        }
289
290        return $cropFactor;
291}
292
293function improve_meta_canon($subarray)
294{
295  global $tpl_meta, $lang, $model;
296  $isEOS = strpos($model, 'Canon EOS') !== false ;
297  if (is_array ($subarray) )
298  {
299        $maxLen = '';  // will be set for the minLen and displayed together
300        foreach ($subarray as $Elem => $subval)
301        {
302                $data= ""; 
303                $key ="";
304                switch ($Elem) 
305                {       
306                    case 1: // added
307                        $key="Macro Mode";
308                        switch($subval) 
309                        {
310                                case 1: $data="Macro"; break;
311                                //case 2: $data="Normal"; break; // do not display if set
312                        }
313                        break;
314                    case 2:
315                        if ($subval  > 0)
316                        {
317                                $key="SelfTimer";
318                                $data.=$subval/10; 
319                                $data=$data.' s';
320                        }
321                        break;         
322                    case 3:
323                        $key="ImageQuality";
324                        switch($subval) 
325                        {
326                                case 2: $data.="Normal"; break;
327                                case 3: $data.="Fine"; break;
328                                case 4: $data.="Raw"; break;
329                                case 5: $data.="Superfine"; break;
330                             // default : $data.' ?';
331                        }
332                        break;                                                   
333                    case 4:
334                        $key="Flash Mode";
335                        switch($subval) 
336                        {
337                                case 0: $data.=''; break; //Off
338                                case 1: $data.="Auto"; break;
339                                case 2: $data.="On"; break;
340                                case 3: $data.="Red Eye Reduction"; break;
341                                case 4: $data.="Slow Synchro"; break;
342                                case 5: $data.="Auto + Red Eye Reduction"; break;
343                                case 6: $data.="On + Red Eye Reduction"; break;
344                                case 16: $data.="External" ; break;
345                        }
346                        break;                                                   
347                    case 5:
348                        $key="Drive";
349                        switch($subval) 
350                        {
351                                case 0: $data.="Single"; break;
352                                case 1: $data.="Continus"; break;
353                                case 2: $data.="Movie"; break;
354                                case 3: $data.="Continuous, Speed Priority"; break;
355                                case 4: $data.="Continus Low"; break;
356                                case 5: $data.="Continus High"; break;
357                                default : $data.=$subval.' ?';
358                        }
359                        break;                                                   
360                    case 7: 
361                        $key="FocusMode";
362                        switch($subval) 
363                        {
364                                case 0: $data.='One-shot AF'; break;
365                                case 1: $data.='AI Servo AF'; break;
366                                case 2: $data.='AI Focus AF'; break;
367                                case 3: $data.='Manual Focus'; break;
368                                case 4: $data.='Single'; break;
369                                case 5: $data.='Continuous'; break;
370                                case 6: $data.='Manual Focus'; break;
371                                default: $data.='Autre ('.$subval.')' ; break; 
372                        } 
373                        break;                                         
374                    case 10: 
375                        $key="ImageSize";
376                        switch($subval) 
377                        {
378                                case 0: $data.='Large'; break;
379                                case 1: $data.='Medium'; break;
380                                case 2: $data.='Small'; break;
381                                //    default : $data.=$subval.' ?';
382                        }
383                        break;                                                 
384                    case 11:
385                        $key="ShootingMode";
386                        switch($subval) 
387                        {
388                                case 0: $data.="Full Auto"; break;
389                                // no display if  off case 1: $data.="Manual"; break;
390                                case 2: $data.="Landscape"; break;
391                                case 3: $data.="Fast Shutter"; break;
392                                case 4: $data.="Slow Shutter"; break;
393                                case 5: $data.="Night"; break;
394                                case 6: $data.="Black & White"; break;
395                                case 7 : $data.="Sepia"; break;
396                                case 8: $data.="Portrait"; break;
397                                case 9: $data. "Sports"; break;
398                                case 10: $data. "Macro / Close-Up"; break;
399                                case 11: $data.="Pan Focus"; break;
400                                //  default : $data.=$subval.' ?';
401                        }
402                        break;
403                   // Contrast, Saturation, Sharpness are only interessting for those shooting direclty in JPG
404                   // Otherwise, it display the RAW value, which are not very relevant IMHO as further enhancements are made in JPG processing
405                   // That's why they are commented
406                   /*case 13:
407                        $key="Contrast";
408                        $data.=$subval;
409                        break;                   
410                    case 14:
411                        $key="Saturation";
412                        $data.=$subval;
413                        break;                                                                           
414                    case 15:
415                        $key="Sharpness";
416                        if ($subval > 3200) {$subval ='Normal';}
417                        $data.=$subval;
418                        break; */
419                    case 17:
420                        $key = "MeteringMode";
421                        switch($subval)
422                        {
423                                case 0: $data ='Default'; break;
424                                case 1: $data ='Spot'; break;
425                                case 2: $data ='Average'; break;
426                                case 3: $data ='Evaluative'; break;
427                                case 4: $data ='Partial'; break;
428                                case 5: $data ='weighted average'; break;
429                                default : $data.=$subval.' ?';
430                        } 
431                        break;
432                    case 19:
433                        $key="AFPointSelected"; 
434                        // seems to be valid only for compact cameras, own tests with EOS camera already retrieve 0.
435                        if ($isEOS) 
436                        { $data=''; }
437                        else
438                        {
439                            switch($subval) 
440                            {
441                                case 0: $data = "";
442                                case 0x3000: $data="None (Manual Focus)"; break;
443                                case 0x3001: $data="Auto Selected"; break;
444                                case 0x3002: $data="Right"; break;
445                                case 0x3003: $data="Centre"; break;
446                                case 0x3004: $data="Left" ; break;
447                                case 0x4001: $data="Auto AF point Selection"; break;
448                                case 0x2005: $data="Manual AF point Selected"; break;
449                                default: $data="Reserved (".$subval.")"; break;
450                            }
451                        }                       
452                        break;
453                    case 20:
454                        $key="ExposureProgram";
455                        switch($subval) 
456                        {
457                                case 0: $data.='Auto'; break;
458                                case 1: $data.='Program'; break;
459                                case 2: $data.='Shutter priority (Tv)'; break;
460                                case 3: $data.='Aperture Priority (Av)'; break;
461                                case 4: $data.='Manual'; break;
462                                case 5: $data.='Depth-of-field'; break;
463                                case 6: $data.='M-Dep'; break;
464                                case 7: $data.='Bulb'; break;
465                        }
466                        break;                   
467                    case 23: // proceed both max and min focal length together
468                        $key="Max. Focal";
469                        if ($subval > 4000)     { $subval /= 1000;}   // for compact cameras
470                        $maxLen=$subval; 
471                        $data=""; // do not show the max len
472                        //$data.=$subval." mm";
473                        break;                                                                           
474                    case 24:
475                        // $key="Min. Focal ";
476                        if ($subval > 4000)     { $subval /= 1000;}  // for compact cameras
477                        if ($subval <> $maxLen)
478                        {
479                                $key="LensFocalRange";
480                                $data=$subval."-".$maxLen."mm";
481                        }
482                        else 
483                        {
484                                $key="FixedFocalLens";
485                                $data.=$subval." mm";
486                        }
487                        break;                     
488                    case 28:
489                        $key="FlashActivity";
490                        switch($subval) 
491                        {
492                                // no display if  off case 0: $data.="Not fired"; break;
493                                case 1: $data.=" Fired"; break;
494                                //     default : $data.=$subval.' ?';
495                        }
496                        break;   
497                    case 29:
498                        $key="FlashDetail";
499                        switch($subval) 
500                        {
501                                case 4: $data="FP sync enabled"; break;
502                                case 7: $data="2nd(rear)-curtain sync used"; break;
503                                case 11: $data="FP sync used"; break;
504                                case 13: $data="internal flash"; break;
505                                case 14: $data="External E-TTL"; break;         
506                        }
507                        break;                 
508                    case 34:
509                        $key ='Stabilization'; // for compact?
510                        switch($subval) 
511                        {
512                                case 0: $data.='Off'; break;
513                                case 1: $data.='On'; break;
514                                case 2: $data.='On, Shot Only'; break;
515                                case 3: $data.='On, Panning';break;
516                                //        default : $data.=$subval.' ?';
517                        }
518                        break;                           
519                    case 39: 
520                        $key ='SpotMeteringMode';
521                        switch($subval) 
522                        {
523                                case 0: $data.='Center'; break;
524                                case 1: $data.='AF point'; break;
525                                //  default : $data.=$subval.' ?';
526                        }
527                        break;
528                } // switch($Elem)
529
530                if ($data!="" )
531                {
532                        if (isset($lang['exif_field_'.$key]))
533                        {       $key = $lang['exif_field_'.$key];}
534                        $tpl_meta['lines'][$key] = $data;; 
535                } 
536        } // foreach
537  } // if(is_array)
538} // function
539
540/*    /////////////////////////////////
541        copy  in config_local.inc.php
542  ///////////////////////////////////
543// exemple of interesting parameters
544$conf['show_exif_fields'] = array(
545        'Model',
546        'ExposureTime',
547        'ExposureBiasValue',
548        'FocalLength',
549    'FNumber',
550    'ISOSpeedRatings',
551    'DateTimeOriginal',
552    'Flash',
553    'Lens',
554    'ModeArray',
555    'UndefinedTag:0x0095'
556)
557
558 /////////////////////////////////
559    Traduction Francaise
560  Copier ce qui suit à la fin de : language/fr_FR/local.lang.php à l'aide de LocalFiles Editor, onglet "Language"
561  ///////////////////////////////////
562// Exif généralistes.
563$lang['exif_field_Make'] = 'Marque';
564$lang['exif_field_Model'] = 'Modèle';
565$lang['exif_field_ExposureCompensation'] = 'Correction Expo';
566$lang['exif_field_ExposureTime'] = 'Vitesse';
567$lang['exif_field_ShutterSpeed'] = 'Vitesse';
568$lang['exif_field_Aperture'] = 'Ouverture diaph.';
569$lang['exif_field_MaxAperture'] = 'Ouverture max';
570$lang['exif_field_FocalLength'] = 'Focale';
571$lang['exif_field_LensName'] = 'Objectif';
572$lang['exif_field_TakenDate'] = 'Le';
573// Exif plus spécifiques.
574$lang['exif_field_ImageQuality'] = 'Qualité Image';
575$lang['exif_field_SelfTimer'] = 'Retardateur';
576$lang['exif_field_Drive'] = "Mode d'acquisition";
577$lang['exif_field_FocusMode'] = 'Mode focus';
578$lang['exif_field_ImageSize'] = 'Taille image';
579$lang['exif_field_ShootingMode'] =  'Mode auomatique';
580$lang['exif_field_Contrast'] = 'Contraste';
581$lang['exif_field_Sharpness'] = 'Netteté';
582$lang['exif_field_MeteringMode'] = 'Mesure Expo.';
583$lang['exif_field_AFPointSelected'] = 'Collimateur AF';
584$lang['exif_field_ExposureProgram'] = 'Prog. Expo';
585$lang['exif_field_LensFocalRange'] = 'Objectif zoom';
586$lang['exif_field_FixedFocalLens'] = 'Objectif fixe';
587$lang['exif_field_FlashActivity'] = 'Flash Opt';
588$lang['exif_field_FlashDetail'] = 'Détail param flash';
589$lang['exif_field_Stabilization'] = 'Stabilisation';
590$lang['exif_field_SpotMeteringMode'] = 'Mesure spot';
591
592 /////////////////////////////////
593    English translation
594  copy at the end of file : language/en_EN/local.lang.php with LocalFiles Editor
595  ///////////////////////////////////
596//translate exif properties in English
597// normal exif
598$lang['exif_field_Make'] = 'Make';
599$lang['exif_field_Model'] = 'Model';
600$lang['exif_field_ExposureCompensation'] = 'Exposure Compensation';
601$lang['exif_field_ExposureTime'] = 'Exposure Time';
602$lang['exif_field_ShutterSpeed'] = 'Shutter Speed';
603$lang['exif_field_Aperture'] = 'Aperture';
604$lang['exif_field_MaxAperture'] = 'Max Aperture';
605$lang['exif_field_FocalLength'] = 'Focal Length';
606$lang['exif_field_LensName'] = 'Lens Name';
607$lang['exif_field_TakenDate'] = 'Taken Date';
608// further exif from MakerNotes
609$lang['exif_field_ImageQuality'] = 'Image Quality';
610$lang['exif_field_SelfTimer'] = 'Self Timer';
611$lang['exif_field_Drive'] = "Drive";
612$lang['exif_field_FocusMode'] = 'Focus Mode';
613$lang['exif_field_ImageSize'] = 'Image Size';
614$lang['exif_field_ShootingMode'] =  'Shooting Mode';
615$lang['exif_field_Contrast'] = 'Contrast';
616$lang['exif_field_Sharpness'] = 'Sharpness';
617$lang['exif_field_MeteringMode'] = 'Metering Mode';
618$lang['exif_field_AFPointSelected'] = 'AF Point Selected';
619$lang['exif_field_ExposureProgram'] = 'Exposure Program';
620$lang['exif_field_LensFocalRange'] = 'Lens Focal Range';
621$lang['exif_field_FixedFocalLens'] = 'Fixed Focal Lens';
622$lang['exif_field_FlashActivity'] = 'Flash Activity';
623$lang['exif_field_FlashDetail'] = 'Flash Detail';
624$lang['exif_field_Stabilization'] = 'Stabilization';
625$lang['exif_field_SpotMeteringMode'] = 'Spot Metering Mode';
626
627///////////////////////////////
628/// Template/Plugin ajustment
629// If you are using the template 'Look Like GBO' and enabling the EXIF as tooltip instead of below the picture, you may need to ajust the width of this tooltip:
630// e.g. 260px instead of 150
631// \plugins\look_like_gbo2\css\sweettitles.css
632// div#toolTip {position:absolute;z-index:1000;width:260px;background:#000;color:gray;border:2px solid #d3d3d3;padding:5px;min-height:1em;-moz-border-radius:5px}
633
634*/
635?>
Note: See TracBrowser for help on using the repository browser.