Modifying which EXIF fields are displayed (PHP code)

Toddler

Joined: 2003-11-11
Posts: 14
Posted: Fri, 2003-11-14 23:20

Does anyone know how to modify which EXIF fields are displayed? It's confusing to me because it looks like the EXIF data is read directly into an array, so the fields are dynamically generated...and that means there's not just a simple place in the code where I can comment out the fields I don't want displayed.

I think the solution is to code some logic to check the value of each field as it is read and then prevent it from being aritten to the array if it isn't wanted. I don't know how to do that in PHP, and plenty of people here obviously do, so I'm hoping someone can tell me how it is done.

Here's the relevant section of code from util.php:

Quote:
function getExif($file) {
global $gallery;

$return = array();
$path = $gallery->app->use_exif;
list($return, $status) = exec_internal(fs_import_filename($path, 1) .
" " .
fs_import_filename($file, 1));

$myExif = array();
if ($status == 0) {
while (list($key,$value) = each ($return)) {
if (trim($value)) {
$explodeReturn = explode(':', $value, 2);
if (isset($myExif[trim($explodeReturn[0])])) {
$myExif[trim($explodeReturn[0])] .= "<br>" .
trim($explodeReturn[1]);
} else {
$myExif[trim($explodeReturn[0])] =
trim($explodeReturn[1]);
}
}
}
}

return array($status, $myExif);
}

Thanks for any advice.

 
Toddler

Joined: 2003-11-11
Posts: 14
Posted: Sat, 2003-11-15 17:57

Nevermind. I figured out how modify util.php to limit the fields that get written to the array and how to control the order.

 
joan
joan's picture

Joined: 2002-10-21
Posts: 3473
Posted: Sat, 2003-11-15 18:27

Great.

Don't forget to share your changes so others can use it, too.

 
Toddler

Joined: 2003-11-11
Posts: 14
Posted: Sat, 2003-11-15 19:48

I'll try to document it once I get it tweaked.

 
Gaile

Joined: 2002-07-20
Posts: 1301
Posted: Sat, 2003-11-15 20:06

Great! :)

Gaile

 
Toddler

Joined: 2003-11-11
Posts: 14
Posted: Mon, 2003-11-17 21:57

After working on this a lot, I've had to do a lot of customizing and even some "hacks" to make it do as I wanted it to do. There is more EXIF info in the EXIF spec than jhead reports normally, so you have to make it run in verbose mode to get the extra data. Then I had to parse the results and make arrays to translate the data (so that instead of "Flash mode: 89" you get "Flash mode: Flash fired, Red-eye reduction mode, Return illumination detected"). I also modified the Capture date/time display to a more friendly format.

I'm happy to contribute, but it's not as simple as a few dozen lines of code. And not being a programmer, this is not easy stuff for me to do. So if enough people really want to know more about this, request it here and I'll try to document it.

 
raymondau
raymondau's picture

Joined: 2004-01-11
Posts: 5
Posted: Thu, 2004-01-15 20:29

seems no one interest in this hack ?

but i m really want to limit the EXIF data being displayed,

there are over 10 lines displayed when enabled the EXIF fields, it seems too much (some is useless) for a guest viewer !

did Toddler found the solution for this yet ??

I would like to know if anyone can solve this problem

Thx a lots !

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Wed, 2004-02-04 07:34

I too am looking and have not had any luck.
getExif(

if ($do_exif) {

$field="EXIF";

it is starting to get blury at this time of the day. I don't think another beer will fix it though. :D

Toddler Have you found a solution? We don't want to reinvent the wheel.

Dave

 
nicomo

Joined: 2004-05-21
Posts: 1
Posted: Fri, 2004-05-21 22:46

hello everybody. i would have only date/time taken from the EXIF data. is that possible?
thanks
best regards, n

 
richbl

Joined: 2004-05-30
Posts: 43
Posted: Thu, 2004-08-26 05:54
Toddler wrote:
Does anyone know how to modify which EXIF fields are displayed? It's confusing to me because it looks like the EXIF data is read directly into an array, so the fields are dynamically generated...and that means there's not just a simple place in the code where I can comment out the fields I don't want displayed.

I think the solution is to code some logic to check the value of each field as it is read and then prevent it from being aritten to the array if it isn't wanted. I don't know how to do that in PHP, and plenty of people here obviously do, so I'm hoping someone can tell me how it is done.

Here's the relevant section of code from util.php:

Quote:
function getExif($file) {
global $gallery;

$return = array();
$path = $gallery->app->use_exif;
list($return, $status) = exec_internal(fs_import_filename($path, 1) .
" " .
fs_import_filename($file, 1));

$myExif = array();
if ($status == 0) {
while (list($key,$value) = each ($return)) {
if (trim($value)) {
$explodeReturn = explode(':', $value, 2);
if (isset($myExif[trim($explodeReturn[0])])) {
$myExif[trim($explodeReturn[0])] .= "<br>" .
trim($explodeReturn[1]);
} else {
$myExif[trim($explodeReturn[0])] =
trim($explodeReturn[1]);
}
}
}
}

return array($status, $myExif);
}

Thanks for any advice.

Hello all,

I just completed the logic for the solution to the problem of how to determine what EXIF fields to display. It requires some understanding of PHP associative array structures, and how Gallery 1.4.4 handles EXIF header information (via jhead).

To implement the solution, a new function called excludeExifFields() is implemented in util.php. The source for this function is as follows:

function excludeExifFields(&$myExif)
  {

  // data source: jhead 2.2, exif.c
  $exif_exclude_list = array
    (
    "File name" => "true",
    "File size" => "true",
    "File date" => "true",
    "Camera make" => "false",
    "Camera model" => "false",
    "Date/Time" => "false",
    "Resolution" => "true",
    "Orientation" => "false",
    "Color/bw" => "false",
    "Flash used" => "false",
    "Focal length" => "false",
    "CCD width" => "false",
    "Exposure time" => "false",
    "Aperture" => "false",
    "Focus dist" => "false",
    "ISO equiv" => "false",
    "Exposure bias" => "false",
    "Whitebalance" => "false",
    "Light Source" => "false",
    "Metering Mode" => "false",
    "Exposure" => "false",
    "Exposure prog" => "false",
    "Jpeg process" => "true",
    "Comment" => "false"
    );
  
  if (!empty($myExif))
    {
    $exif_exclude_array = array_keys($exif_exclude_list, "true");        
    foreach ($exif_exclude_array as $exif_exclude_key)
      {
      foreach ($myExif as $key => $value)
        {
        if ($key == $exif_exclude_key)  
          {
          unset($myExif[$key]);      
          }
        }
      }
    }
    
  }

The value, $myExif, passed in (by reference) is the associative array holding EXIF fields and field values created when a call is made into getExif() in util.php.

Note the reference to jhead, which is the library that Gallery calls into to perform EXIF header extraction. The associative array $exif_exclude_list is derived from this jhead data. Unfortunately, these EXIF fields are hardcoded into the jhead exif.c file, which will require manual updating in the event of a update to EXIF field structures (as proposed in the JEITA EXIF 2.2 specification, released April 2002).

To exclude an EXIF field, set the array value from false to true.

The remaining logic first parses $exif_exclude_list into a list (associative array) of those EXIF fields to exclude. The logic then iterates on the $myExif array, removing (call to unset()) those excluded fields.

To correctly make use of excludeExifFields(), call this function after $myExif is created, but just before Gallery routines display or act upon $myExif.

As an example, in the source fragment below, I implemented the call into excludeExifFields() in util.php, function displayPhotoFields(). Note the #### indicating changes in logic:

...

  if ( $withExif && ($gallery->app->use_exif && (eregi("jpe?g\$", $photo->image->type)))) 
    {
    $myExif = $gallery->album->getExif($index, isset($forceRefresh));
    
    if ($myExif)
      {
      // following line commented out because we were losing
      // comments from the Exif array.  This is probably due
      // to differences in versions of jhead.
      array_shift($myExif); // get rid of file name at beginning
      
// ####
      excludeExifFields($myExif);
      $tables[_("EXIF Data")]  = $myExif;
      }
    }

  if (! isset($tables))
    {
    return;
    }

...

best of luck,

rich

 
sgartner
sgartner's picture

Joined: 2003-10-05
Posts: 16
Posted: Mon, 2005-04-18 04:00

Hello all,

I solved this a completely different way. The gallery script simply runs Jhead and then parses out the lines looking for colons to separate out the columns so that the formatting is clean. I didn't want to hack the PHP code since I would have to do that for every release of Gallery. Instead, I wrote a script (batch file) that runs Jhead in verbose mode and uses SED to remove what I didn't like. Here is the script (called jhead.cmd):

--- cut here ---
echo off
c:\gallerybin\jhead -v "%1" | sed -f "c:\gallerybin\jhead.sed"
--- cut here ---

I keep all of the supporting executables for gallery in gallerybin, so use your own paths. The SED program is where the complexity is:

--- cut here ---
# First select the extra rows we want by making sure they
# are formatted with colons.
s/ImageDescription = /Exif Image Description :/
s/Copyright = /Copyright :/
s/JPEG image is/JPEG image is:/

# Now delete any rows that don't have colons in them
/:/!d

# Now delete some random garbage
/DateTime/d

/File size/!{
/bytes/d
}

# Now clean up the data
s/?"//
s/"//
s/copyright .. 200/copyright \& 200/

# Reformat the date
s%Date/Time.*: \(....\):\(..\):\(..\) \(.*\)%Date/Time:\2/\3/\1 \4%
s%File date.*: \(....\):\(..\):\(..\) \(.*\)%File date:\2/\3/\1 \4%
--- cut here ---

If you don't know SED you might be lost by this but the most important parts are the first and the last. The first changes the name=value format to name:value for certain items that I want to appear in Gallery. The last reformats the dates into a format I like better than the EXIF date format. You can play with commenting out lines to see what happens (just put a "#" in front of any line you don't like).

Of course, if you are running Windows you will need to install some version of SED (I use Cygwin). For most of you *nix guys out there you won't have any problems.

You can see an example of my output here:
http://pics.pingbot.com:8002/gallery/sgartner-nature/Boise_downtown_panorama_1

To get Cygwin: http://www.cygwin.com/

Good luck.

 
mchiba

Joined: 2005-04-22
Posts: 6
Posted: Mon, 2005-04-25 06:53

Does anyone know how to modify the exif data display for the version 1.5???

 
sgartner
sgartner's picture

Joined: 2003-10-05
Posts: 16
Posted: Tue, 2005-04-26 08:23
mchiba wrote:
Does anyone know how to modify the exif data display for the version 1.5???

Can you be more specific. The method I just outlined works with 1.5.

 
mchiba

Joined: 2005-04-22
Posts: 6
Posted: Wed, 2005-04-27 13:26
sgartner wrote:
mchiba wrote:
Does anyone know how to modify the exif data display for the version 1.5???

Can you be more specific. The method I just outlined works with 1.5.

how to determine which EXIF data to be displayed on the photo properties pop-up?

 
sgartner
sgartner's picture

Joined: 2003-10-05
Posts: 16
Posted: Thu, 2005-04-28 00:09
mchiba wrote:
How to determine which EXIF data to be displayed on the photo properties pop-up?

The script takes whatever fields are output by JHEAD (which I assume is all of them) and allows you to add or remove fields from the list. If you send me the JHEAD output for one of your pictures with information about which fields, I can probably adjust the script in a couple of minutes and repost it.

However, before you do that, I would suggest that you get the script, as shown above, working on your site.

 
joshcali

Joined: 2007-10-03
Posts: 19
Posted: Fri, 2009-02-06 08:41

I found another small code solution for this in gallery 1.5.7

I know it's been a while since this thread, but I wanted to include my mod here in case others needed the solution

in util.php, there's a part of the code that actually now includes a section of exif headers to exclude!

on line 591, there is a line:
$unwantedFields = array('File name');

you can add any field to this like:
$unwantedFields = array('File name', 'City', 'Keywords');
and these will not show up.

--
I decided it would be easier to put in the fields I wanted rather than the fields I didn't so I made this modification to util.php. Here's the full function for getExif
I've commented where the mods are...

Quote:
function getExif($file) {
global $gallery;

$return = array();
$myExif = array();
$unwantedFields = array();

switch(getExifDisplayTool()) {
case 'exiftags':
if (empty($gallery->app->exiftags)) {
break;
}
$path = $gallery->app->exiftags;
list($return, $status) = @exec_internal(fs_import_filename($path, 1) .' -au '.
fs_import_filename($file, 1));
break;

case 'jhead':
if (empty($gallery->app->use_exif)) {
break;
}
$path = $gallery->app->use_exif;
list($return, $status) = @exec_internal(fs_import_filename($path, 1) .' '. //. ' -v ' .
fs_import_filename($file, 1));
//Josh Modification
$unwantedFields = array('File name');
$wantedFields = array('Keywords', 'City');
//original section
/*
$unwantedFields = array('File name');
*/
break;

default:
return array(false,'');
break;
}

if ($status == 0) {
foreach ($return as $value) {
$value = trim($value);
if (!empty($value)) {
$explodeReturn = explode(':', $value, 2);
$exifDesc = trim(htmlentities($explodeReturn[0]));
$exifData = trim(htmlentities($explodeReturn[1]));
// Josh Mod

if(!empty($exifData) &&
!in_array($exifDesc, $unwantedFields) &&
in_array($exifDesc, $wantedFields) )
{
if (isset($myExif[$exifDesc])) {
$myExif[$exifDesc] .= ", ";
} else {
$myExif[$exifDesc] = '';
}

$myExif[$exifDesc] .= trim($exifData);
}
/* Original Code Section:
if(!empty($exifData) &&
!in_array($exifDesc, $unwantedFields) &&
!isset($myExif[$exifDesc]))
{
if (isset($myExif[$exifDesc])) {
$myExif[$exifDesc] .= "<br>";
} else {
$myExif[$exifDesc] = '';
}

$myExif[$exifDesc] .= trim($exifData);
}
*/
}
}
}

return array($status, $myExif);
}

If you notice, I also modified this to ignore if a particular metadata had already been entered, and then it appends additional exif data with a ", " instead of the "<br>".
I did this to fix the fact that it was only including the first keyword from the keywords field
hope this helps someone :)