Author Topic: [Mod] EXIF 0.3  (Read 309447 times)

0 Members and 1 Guest are viewing this topic.

Offline fatman

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • http://photo.nixrex.com
[Mod] EXIF 0.3
« on: December 27, 2002, 04:23:00 AM »
I always want somebody make 4images to have exif support, at last, I write this MOD for show the EXIF info of the JPG file in the detail page. Originally, I wrote one was using the PHP built in function to read the data, however, I found the function in php 4.1 is not read all tag of exif and I did not want to make a php 4.2 installation. Finally, I find a php exif library call Exifer is for ver 0.1 & 0.2.

Now, for version 0.3, it use the php built in exif function, so you must have the php 4.2 or above and enable the exif option. I have add a function for choosing which exif field to display( actually, i only parse 2 sections(IFD0, EXIF) in exif header, other section seem unless for information) It work OK on my Canon D60 image file, but I did not have parse the MakerNote filed.

1. Create a file exif.php at "includes/exif.php" and the content is:
the first line of code (EXIF_CONTROL) is to control display all field or chosen field.
the second line of code (EXIF_FILTER) is to control which filed to display.
Code: [Select]
<?php

/*
4images EXIF MOD 
Version : 0.3
Date: 2003-01-17
By: fatman (fatman_li@yahoo.com.hk)

*/

// true: enable the field filter
// false: disable the field filter
define('EXIF_CONTROL'true);

// add the field name for show in exif section 
// remember the field name with the colon ":"
define('EXIF_FILTER'"
Model:
Orientation:
ExposureTime:
FNumber:
ISOSpeedRatings:
ExposureBiasValue:
MeteringMode:
Flash:
FocalLength:
ColorSpace:
"
);

function 
exif_filter_control() {
 
return EXIF_CONTROL;
}

function 
exif_filter($name) {
 
if (strpos(EXIF_FILTER, ($name ":")) > 0) {
 
 return true;
 
} else {
 
 return false;
 
}
 

}


function 
exif_get_str_val($val) {
 
$val = (substr($val0strpos($val"/"))) / (substr($valstrpos($val"/") + 1));
 
return $val;
}

function 
exif_parse_value($name$val) {
 
switch($name) {
 
  case "Orientation"
 
   if($val==1$val "Normal";
 
   if($val==2$val "Mirrored";
 
   if($val==3$val "Upsidedown";
 
   if($val==4$val "Upsidedown Mirrored";
 
   if($val==5$val "90deg CW Mirrored";
 
   if($val==6$val "90deg CCW";
 
   if($val==7$val "90deg CCW Mirrored";
 
   if($val==8$val "90deg CW";
 
   break;
 
  case "ResolutionUnit"
 
   if($val==1$val "No Unit";
 
   if($val==2$val "Inch";
 
   if($val==3$val "Centimeter";
 
   break;
 
  case "YCbCrPositioning"
 
   if($val==1$val "Pixel Array";
 
   if($val==2$val "Datum Point";
 
   break;
 
  case "ExposureTime"
 
   $val $val " seconds";
 
   break;
 
  case "FNumber"
 
   $val "F/" exif_get_str_val($val);
 
   break;
 
  case "ExposureProgram"
 
   if($val==1$val "Manual control";
 
   if($val==2$val "Program normal";
 
   if($val==3$val "Aperture priority";
 
   if($val==4$val "Shutter priority";
 
   if($val==5$val "Program creative(slow program)";
 
   if($val==6$val "Program action(high-speed program)";
 
   if($val==7$val "Portrait mode";
 
   if($val==8$val "Landscape mode";
 
   break;    
   
case "ExifVersion"
 
   $val round($val 1002);
 
   break;
 
  case "ComponentsConfiguration"
 
   $val bin2hex($val);
 
   $val str_replace("01","Y",$val);
 
   $val str_replace("02","Cb",$val);
 
   $val str_replace("03","Cr",$val);
 
   $val str_replace("04","R",$val);
 
   $val str_replace("05","G",$val);
 
   $val str_replace("06","B",$val);
 
   $val str_replace("00","",$val);    
    
break;
 
  case "CompressedBitsPerPixel"
 
   $val exif_get_str_val($val);
 
   break;
 
  case "ShutterSpeedValue"
 
   $val "1/" round(pow(2exif_get_str_val($val))) . " seconds";
 
   break;
 
  case "ApertureValue"
 
   $val "F/" round(pow(sqrt(2), exif_get_str_val($val)),1);
 
   break;
 
  case "BrightnessValue "
 
   $val exif_get_str_val($val);
 
   break;    
   
case "ExposureBiasValue":
 
   if ((substr($val0strpos($val"/"))) == "0") {
 
     $val "0 Step";
 
   } else {
 
     $val $val " Step";
 
   }
 
   break;
 
  case "MaxApertureValue"
 
   $val "F/" round(pow(sqrt(2), exif_get_str_val($val)),1);
 
   break;
 
  case "SubjectDistance"
 
   $val exif_get_str_val($val) . " M";
 
   break;    
   
case "MeteringMode"
 
   if($val==0$val "Unknown";
 
   if($val==1$val "Average";
 
   if($val==2$val "Center Weighted Average";
 
   if($val==3$val "Spot";
 
   if($val==4$val "Multi-spot";
 
   if($val==5$val "Multi-segment";
 
   if($val==6$val "Partial";
 
   if($val==255$val "Other"   
    
break;
 
  case "LightSource"
 
   if($val==0$val "Unknown";
 
   if($val==1$val "Daylight";
 
   if($val==2$val "Fluorescent";
 
   if($val==3$val "Tungsten";
 
   if($val==10$val "Flash";
 
   if($val==17$val "Standard light A";
 
   if($val==18$val "Standard light B";
 
   if($val==19$val "Standard light C";
 
   if($val==20$val "D55";
 
   if($val==21$val "D65";
 
   if($val==22$val "D75";
 
   if($val==255$val "Other";
 
   break;    
   
case "Flash"
 
   if($val==0$val "No Flash";
 
   if($val==1$val "Flash fired";
 
   if($val==5$val "Flash fired but strobe return light not detected";
 
   if($val==7$val "Flash fired and strobe return light detected";
 
   if($val==9$val "Undefined"
 
   break;
 
  case "FocalLength"
 
   $val exif_get_str_val($val) . " mm";
 
   break; 
 
  case "FlashPixVersion"
 
   $val round($val 1002);
 
   break;
 
  case "ColorSpace"
 
   if($val==1$val "sRGB";
 
   if($val=='65535'$val "Uncalibrated";
 
   break;
 
  case "FocalPlaneXResolution"
 
   $val round(exif_get_str_val($val));
 
   break; 
 
  case "FocalPlaneYResolution"
 
   $val round(exif_get_str_val($val));
 
   break;            
   
case "FocalPlaneResolutionUnit"
 
   if($val==1$val "No Unit";
 
   if($val==2$val "Inch";
 
   if($val==3$val "Centimeter";
 
   break;
 
  case "SensingMethod"
 
   if($val==2$val "1 chip color area sensor";
 
   break;
 
  case "FileSource":
 
   $val bin2hex($val);
 
   if($val==0x03$val "Digital still camera"  
    
break;
 
  case "FileSource":
 
   $val bin2hex($val);
 
   if($val==0x01$val "Directly photographed"  
    
break;




 
  }
 
  
 return $val
;
}
?>


2. Open "includes/functions.php" and add after:

Code: [Select]
if (!defined('ROOT_PATH')) {
 die("Security violation");
}

this code:
Code: [Select]
include(ROOT_PATH.'includes/exif.php');
3. Open "includes/functions.php" and add after:
Code: [Select]
if ($detailed_view && isset($info['APP13'])) {
  $iptc_array = get_iptc_info($info['APP13']);
  $bgcounter = 0;
  foreach ($iptc_array as $key => $val) {
  $row_bg_number = ($bgcounter++ % 2 == 0) ? 1 : 2;
  $site_template->register_vars(array(
  "iptc_value" => $val,
  "iptc_name" => $lang['iptc_'.$key],
  "row_bg_number" => $row_bg_number
  ));
  $iptc_info .= $site_template->parse_template("iptc_bit");
  }
  }

this code:
Code: [Select]
$exif_info = "";
  if ($image_info[2] == 2 && $detailed_view && !is_remote($media_file_name)) {
  $exif = exif_read_data ($media_src,'IFD0');
  $bgcounter = 0;
  if ($exif) {
  $exif = exif_read_data ($media_src,0,true);
  foreach($exif as $key=>$section) {
  if (($key == "IFD0") || ($key == "EXIF")) {
  foreach($section as $name=>$val) {
  if (!(exif_filter($name)) && exif_filter_control()) continue;
  $row_bg_number = ($bgcounter++ % 2 == 0) ? 1 : 2;
  $site_template->register_vars(array(
  "exif_value" => exif_parse_value($name, $val),
  "exif_name" => $name . ":",
  "row_bg_number" => $row_bg_number
  ));
  $exif_info .= $site_template->parse_template("exif_bit");
  }
  }
  }
  }
  }

4. Open "includes/functions.php" and find:
Code: [Select]
$site_template->register_vars(array(
  "media_src" => $media_src,
  "media_icon" => $media_icon,
  "image_name" => $image_name,
  "width_height" => $width_height,
  "width" => $width,
  "height" => $height,
  "iptc_info" => $iptc_info
  ));

replace with:
Code: [Select]
$site_template->register_vars(array(
  "media_src" => $media_src,
  "media_icon" => $media_icon,
  "image_name" => $image_name,
  "width_height" => $width_height,
  "width" => $width,
  "height" => $height,
  "iptc_info" => $iptc_info,
  "exif_info" => $exif_info
  ));

5. Open template detail.html and add after:
Code: [Select]
{if iptc_info}
<br />
<table width="100%" border="0" cellspacing="0" cellpadding="1">
  <tr>
  <td class="bordercolor">
  <table width="100%" border="0" cellpadding="3" cellspacing="0">
  <tr>
  <td class="head1" valign="top" colspan="2">IPTC Info</td>
  </tr>
{iptc_info}
  </table>
  </td>
  </tr>
  </table>
  {endif iptc_info}
this code

Code: [Select]
{if exif_info}
<br />
<table width="100%" border="0" cellspacing="0" cellpadding="1">
  <tr>
  <td class="bordercolor">
  <table width="100%" border="0" cellpadding="3" cellspacing="0">
  <tr>
  <td class="head1" valign="top" colspan="2">EXIF Info</td>
  </tr>
{exif_info}
  </table>
  </td>
  </tr>
  </table>
  {endif exif_info}

6. Create a new template exif_bit.html
Code: [Select]
<tr>
 <td valign="top" class="row{row_bg_number}"><b>{exif_name}</b></td>
 <td valign="top" class="row{row_bg_number}">{exif_value}</td>
</tr>
« Last Edit: February 07, 2006, 05:45:48 AM by V@no »

Offline mantra

  • Sr. Member
  • ****
  • Posts: 358
    • View Profile
    • DREAM WITH MANTRA
How about [ descript.ion ] in ACDsee can we use this
« Reply #1 on: December 27, 2002, 05:35:42 AM »
How about [ descript.ion ] in ACDsee, can we use this for read all the tags too.  ( just wonder ???)

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] EXIF 0.3
« Reply #2 on: December 27, 2002, 05:43:29 AM »
I dont see any difference between v0.1 and v0.2, its shows exact same info, no new field and same funny ceracters in MakerNote, even though when I checked that picture at the site it showed me clear text info...
then I deleted
Code: [Select]
include('exif.php'); to check if the script give any erorros - and still it print EXIF information...well, I have PHP v4.2.3, maybe it uses only build in EXIF_INFO...
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline fatman

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • http://photo.nixrex.com
Re: How about [ descript.ion ] in ACDsee can we use this
« Reply #3 on: December 27, 2002, 06:52:12 AM »
Quote from: mantra
How about [ descript.ion ] in ACDsee, can we use this for read all the tags too.  ( just wonder ???)


I don't use ACDsee, so I don't know.

Offline fatman

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • http://photo.nixrex.com
[Mod] EXIF 0.3
« Reply #4 on: December 27, 2002, 06:55:19 AM »
Quote from: V@no
I dont see any difference between v0.1 and v0.2, its shows exact same info, no new field and same funny ceracters in MakerNote, even though when I checked that picture at the site it showed me clear text info...
then I deleted
Code: [Select]
include('exif.php'); to check if the script give any erorros - and still it print EXIF information...well, I have PHP v4.2.3, maybe it uses only build in EXIF_INFO...


then, it may because you have not modified following code.
it use different function call, it should be error if remark the include line.
Quote

3. Open "includes/functions.php" and add after:
Code: [Select]
     if ($detailed_view && isset($info['APP13'])) {
        $iptc_array = get_iptc_info($info['APP13']);
        $bgcounter = 0;
        foreach ($iptc_array as $key => $val) {
          $row_bg_number = ($bgcounter++ % 2 == 0) ? 1 : 2;
          $site_template->register_vars(array(
            "iptc_value" => $val,
            "iptc_name" => $lang['iptc_'.$key],
            "row_bg_number" => $row_bg_number
          ));
          $iptc_info .= $site_template->parse_template("iptc_bit");
        }
      }


this code:
Code: [Select]
     $exif_info = "";
      if (($file_extension == "jpg") || ($file_extension == "jpeg")) {
        $exif = read_exif_data_raw($media_src,0);
        $bgcounter = 0;
        if ($exif > "") {
          foreach($exif as $key=>$section) {
         
            if (is_array($section)) {
              foreach($section as $name=>$val) {
                $row_bg_number = ($bgcounter++ % 2 == 0) ? 1 : 2;
                $site_template->register_vars(array(
                  "exif_value" => ((is_array($val)) ? "" : $val),
                  "exif_name" => $name . ":",
                  "row_bg_number" => $row_bg_number
                ));
                $exif_info .= $site_template->parse_template("exif_bit");              
              if (is_array($val)) {
               foreach($val as $s_name=>$s_val) {
                    $site_template->register_vars(array(
                      "exif_value" => $s_val,
                      "exif_name" => "&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;" . $s_name . ":",
                      "row_bg_number" => $row_bg_number
                    ));
                    $exif_info .= $site_template->parse_template("exif_bit");              
               }
                }
              }
            }
          }
        }



I have get one of the image from your homepage and put to my server for testing.(I will delete it later), you can take a look.

http://come.no-ip.com/details.php?image_id=1315
http://photo.nixrex.com/details.php?image_id=233

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] EXIF 0.3
« Reply #5 on: December 27, 2002, 05:15:11 PM »
Sry, my bad...was changing in one 4images code and tested on another one.... :oops:
but, now I get blank screen and phperor.log shows me this error:
Quote
[27-Dec-2002 11:05:10] PHP Parse error:  parse error, unexpected $ in e:\www\4images\includes\functions.php on line 1280
[27-Dec-2002 11:05:10] PHP Fatal error:  Call to undefined function:  get_category_dropdown() in e:\www\4images\includes\page_header.php on line 132
on line 1280 in functions.php is " ?> "
in page_header.php on line 132 is "$category_dropdown_selfjump = get_category_dropdown($cat_id, 1);"

if I leave include and put code from v0.1 it works fine.
my spec:
WindowsXP, Apache 1.3.26, PHP 4.2.3, MySQL 3.23.52
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline fatman

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • http://photo.nixrex.com
[Mod] EXIF 0.3
« Reply #6 on: December 27, 2002, 07:11:54 PM »
Oh!!! I miss one "}"

there should be seven "}" at the end
Code: [Select]

                    $exif_info .= $site_template->parse_template("exif_bit");                  
                   }
                }
              }
            }
          }
        }
      }

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] EXIF 0.3
« Reply #7 on: December 27, 2002, 08:36:45 PM »
hmm....strange, well, got it work, but it doesnt show as much as on your site:
http://come.no-ip.com/details.php?image_id=1315
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline fatman

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • http://photo.nixrex.com
[Mod] EXIF 0.3
« Reply #8 on: December 28, 2002, 06:36:52 AM »
should be some program error..
the last field is "unknown::", it got two colons.  Normally, it should only got one ":" per field, there may be some looping problem.

Any other have tried it and succeed?

Offline jengwen

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
    • http://www.jenrichardsphotography.com
Works great!
« Reply #9 on: January 09, 2003, 05:47:51 PM »
This worked great for me and did exactly what I wanted.  Thanks!  

I do want to note that I had to change the includes statements to have more of a path with them (I just found a different includes statement and copied the first part of it).  Then, everything worked perfectly!

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] EXIF 0.3
« Reply #10 on: January 10, 2003, 04:44:43 AM »
I had to turn this feature off, because now my phperror.log full of this:
Quote
[06-Jan-2003 04:19:33] PHP Warning:  Invalid TIFF start (1) in e:\www\includes\functions.php on line 425
[06-Jan-2003 05:03:35] PHP Warning:  Incorrect APP1 Exif Identifier Code in e:\www\includes\functions.php on line 425

it was on some images, but then I used "EXIFER" that I downloaded from www.download.com and now I get those errors for each picture...
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline jengwen

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
    • http://www.jenrichardsphotography.com
Some data not correct
« Reply #11 on: January 15, 2003, 09:23:55 PM »
Quote
Size: 16
Identifier: JFIF
ExtensionCode: 01
Data: HH
ImageDescription: Green Bay Packers vs. Detroit Lions
Make: Canon
Model: Canon EOS D60
Orientation: 65536
xResolution: 0.013888888888889
yResolution: 0.013888888888889
ResolutionUnit: 131072
Software: Adobe Photoshop 7.0
DateTime: 2003:01:12 22:04:02
Copyright: Copyright 2002 Jennifer L. Richards
ExifOffset: 296
ExposureTime: 750 sec
FNumber: f 0.17857142857143
ExposureProgram: Unknown: 196608
ISOSpeedRatings: 52428800
ExifVersion: version 0
DateTimeOriginal: 2002:11:10 14:34:30
DateTimedigitized: 2002:11:10 14:34:30
ExposureBiasValue: 1000/0 EV
MeteringMode: Unknown: 327680
LightSource: Unknown
Flash: No Flash
FocalLength: 0.0033333333333333 mm
UserComment: ASCII  
ColorSpace: Uncalibrated
ExifImageWidth: 562 pixels
ExifImageHeight: 640 pixels
Compression: Unknown: 393216
xResolution: 0.013888888888889
yResolution: 0.013888888888889
ResolutionUnit: 131072
JpegIFOffset: 926
JpegIFByteCount: 6199


Some of the fields seem to work, but some don't.  I am particularily concerned with ISO, Aperature/Fnumber, and Shutter Speed.  If you go to www.jenrichardsphotography.com you can see the problem on any image you select.  I also tried uploading an image on your site, ran it through your EXIFER and the info is wrong there too.  I have looked at the code and can't find the problem.  Also, do you have any plans to parse out the MakerNote fields for Canon?  I was going to try to do it myself, but can't quite get a handle on how the IFD tags work.  Lastly, is there a way to display only certain EXIF fields on the detail page instead of all of them?

Offline fatman

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • http://photo.nixrex.com
Re: Some data not correct
« Reply #12 on: January 16, 2003, 11:25:14 AM »
I am also using the D60, but I don't have your problem....

You may take a look on
http://photo.nixrex.com/details.php?image_id=182

Which version of firmware you are using? are you using the RAW format?

Anyway, I am tring to make the EXIF MOD to use PHP 4.2 built in functions
rather than the exifer.  After this, I will try to write the EXIF field display control.

Quote from: jengwen

Some of the fields seem to work, but some don't.  I am particularily concerned with ISO, Aperature/Fnumber, and Shutter Speed.  If you go to www.jenrichardsphotography.com you can see the problem on any image you select.  I also tried uploading an image on your site, ran it through your EXIFER and the info is wrong there too.  I have looked at the code and can't find the problem.  Also, do you have any plans to parse out the MakerNote fields for Canon?  I was going to try to do it myself, but can't quite get a handle on how the IFD tags work.  Lastly, is there a way to display only certain EXIF fields on the detail page instead of all of them?

Offline fatman

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • http://photo.nixrex.com
[Mod] EXIF 0.3
« Reply #13 on: January 16, 2003, 12:28:27 PM »
I have modified one line of code of PART 3, it should improve the performance when listing the thumbnail.

from

Quote

      if (($file_extension == "jpg") || ($file_extension == "jpeg")) {


to

Quote

      if ((($file_extension == "jpg") || ($file_extension == "jpeg")) && ($detailed_view)) {

Offline jengwen

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
    • http://www.jenrichardsphotography.com
[Mod] EXIF 0.3
« Reply #14 on: January 16, 2003, 08:02:02 PM »
I do shoot in raw CRW format, then convert to TIF, and then JPG.  Do you?  Perhaps my data is getting corrupted along the way, although I thought I tried them with other EXIF readers and everthing is fine.  I might have only tried the TIFs and not JPGs, so will have to verify that.  Thanks for letting me check out your website.

 

Post your comments here