Template modifications - add some EXIF data near the intermediate image Template modifications - add some EXIF data near the intermediate image
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Template modifications - add some EXIF data near the intermediate image

Started by wuschel_lux, March 12, 2010, 07:42:52 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

wuschel_lux

Hi all,

I started to modify the curve theme. The changes done on the theme.php are mainly for the intermediate image view page.
Here you can find the actual result: http://www.volleyball.lu/newfotogallery/displayimage.php?pid=31

Now I am looking for some code to add several EXIF information near the image (in the example page marked as placeholders). These are EXIF Info: {MODEL} {FOCALLENGTH} {FNUMBER} {EXPOSURETIME} {ISO}.

In this thread Joachim gave me already some hints how to fill {PLACEHOLDERS} with content: http://forum.coppermine-gallery.net/index.php/topic,64059.msg318237.html#msg318237, but my skills are not good enough to point out how to get out of the DB the right part of the EXIF information.

So if someone could help me to code for one EXIF value, I could hopefully make the rest.

Thanks in advance

Αndré

From displayimage.php:
   if ($CONFIG['read_exif_data']) {
   
       $exif = exif_parse_file($metadata_path, $CURRENT_PIC_DATA['pid']);
   
       if (is_array($exif)) {
           array_walk($exif, 'sanitize_data');
           $info = array_merge($info, $exif);
       }
   }

That code adds the exif data to the file information div. Just add that code to your theme.php and grab the desired data from $info.

Joachim Müller

Do a print_r($info);at the spot where you want to use it to get an idea what's inside the array if you can't figure out by just looking at the code. If you're using it inside a function, don't forget that you may have to change the scope using the global command.

wuschel_lux

Thanks for the feedback but I still have my problems.

Adding the code to my theme.php will produce following error message:
Fatal error: Call to undefined function exif_parse_file() in /home/www/web858/web858u1/html/newfotogallery/themes/curve_vb/theme.php on line 397

So must I include or call an other file?

And how can I add the print_r($info); in part

$template_display_media = <<<EOT
<tr>
     ...
          EXIF Info: {???}
     ...
</tr>
EOT;


I Found this in the doc:
print <<< EOT
<h1>Hello {$bla}</h1>
EOT;
}

Αndré

Quote from: wuschel_lux on March 12, 2010, 09:01:57 AM
Adding the code to my theme.php will produce following error message:
Fatal error: Call to undefined function exif_parse_file() in /home/www/web858/web858u1/html/newfotogallery/themes/curve_vb/theme.php on line 397

So must I include or call an other file?
You have to include include/exif_php.inc.php.


Quote from: wuschel_lux on March 12, 2010, 09:01:57 AM
And how can I add the print_r($info); in part

$template_display_media = <<<EOT
<tr>
     ...
          EXIF Info: {???}
     ...
</tr>
EOT;

You mustn't add it there. Just add it below
$info = array_merge($info, $exif);

wuschel_lux

Quote from: Αndré on March 12, 2010, 09:27:42 AM
You have to include include/exif_php.inc.php.
when including I get this new error:
Fatal error: Cannot redeclare exif_parse_file() (previously declared in /home/www/web858/web858u1/html/newfotogallery/include/exif_php.inc.php:26) in /home/www/web858/web858u1/html/newfotogallery/include/exif_php.inc.php on line 96

Αndré

Quote from: wuschel_lux on March 12, 2010, 09:01:57 AM
Adding the code to my theme.php will produce following error message:
Fatal error: Call to undefined function exif_parse_file() in /home/www/web858/web858u1/html/newfotogallery/themes/curve_vb/theme.php on line 397
I justed tested that and got no error message. You don't need to include the file include/exif_php.inc.php.

Insert
    if ($CONFIG['read_exif_data']) {
   
        $exif = exif_parse_file($metadata_path, $CURRENT_PIC_DATA['pid']);
   
        if (is_array($exif)) {
            array_walk($exif, 'sanitize_data');
            print_r($exif);
        }
    }

before     $params = array('{CELL_HEIGHT}' => '100',
        '{IMAGE}' => $CURRENT_PIC_DATA['header'].$CURRENT_PIC_DATA['html'].$CURRENT_PIC_DATA['footer'],
        '{ADMIN_MENU}' => $CURRENT_PIC_DATA['menu'],
        '{TITLE}' => bb_decode($CURRENT_PIC_DATA['title']),
        '{CAPTION}' => bb_decode($CURRENT_PIC_DATA['caption']),

wuschel_lux

ok so I have the code on the right place and the error message is gone.
That was the good news, the bad one, I have no output on the screen  :(

Αndré


wuschel_lux

I added the line
global $metadata_path, $exif;
already before, but no output.

Hope that is what Joachim and you are trying to tell me?

Αndré

Sorry. I should had a deeper look at the code where I copied the section from.

This code works (global is not necessary):
    if ($CONFIG['read_exif_data']) {
        $path_to_pic = $CONFIG['fullpath'] . $CURRENT_PIC_DATA['filepath'] . $CURRENT_PIC_DATA['filename'];
        $path_to_orig_pic = $CONFIG['fullpath'] . $CURRENT_PIC_DATA['filepath'] . $CONFIG['orig_pfx'] . $CURRENT_PIC_DATA['filename'];
        $metadata_path = file_exists($path_to_orig_pic) ? $path_to_orig_pic : $path_to_pic;
        $exif = exif_parse_file($metadata_path, $CURRENT_PIC_DATA['pid']);
        if (is_array($exif)) {
            array_walk($exif, 'sanitize_data');
        }
        print_r($exif);
    }

wuschel_lux

Hey André many, many thanks for your support. The array is now shown on the top of the page.
Here an example:
Array ( [DateTime Original] => 2009:12:05 19:41:06 [Exposure Program] => Manual [Exposure Time] => 1/500 sec [FNumber] => f/2.8 [Flash] => No Flash [Focal length] => 85 mm [ISO] => 3200 [Make] => Canon [Metering Mode] => Multi-Segment [Model] => Canon EOS 7D )

So this works fine and the final solution is near.

wuschel_lux

so with adding following lines I got the expected result based on the array in the post before:
'{MODEL}' => $exif['Model'],
'{FOCALLENGTH}' => $exif['Focal length'],
'{FNUMBER}' => $exif['FNumber'],
'{EXPOSURETIME}' => $exif['Exposure Time'],
'{ISO}' => $exif['ISO'],


The output is as expected:
Equipment: Canon EOS 7D (85 mm, f/2.8, 1/500 sec, ISO 3200)

But there is still a small cosmetig error, when the EXIF data is "empty" the output is
Equipment: (, , , ISO )

My problem here I can not insert a php "if" line to my code. Something like this:
$template_display_media = <<<EOT
<tr>
     ...
           if($exif['Model'] == "" || $exif['Focal length'] == "" || ...){echo "Equipment not available";} else {echo "Equipment: {MODEL} ({FOCALLENGTH}, {FNUMBER}, {EXPOSURETIME}, ISO {ISO})";}
     ...
</tr>
EOT;


Joachim Müller

Well, I can't see the point in populating so many placeholder tokens anyway - just populating one string will do the trick:
$exif_bracket_array = array('Focal length', 'FNumber', 'Exposure Time', 'ISO');
$exif_string = '';
foreach ($exif_bracket_array as $key) {
$exif_string .= $exif[$key] . ', ';
}
$exif_string = rtrim($exif_string);
$exif_string = rtrim($exif_string, ',');
if ($exif_string != '') {
$exif_string = '(' . $exif_string . ')';
}
if ($exif['Model'] != '') {
$exif_string = $exif['Model'] . ' ' . $exif_string;
}

    $params = array('{CELL_HEIGHT}' => '100',
        '{IMAGE}' => $CURRENT_PIC_DATA['header'].$CURRENT_PIC_DATA['html'].$CURRENT_PIC_DATA['footer'],
        '{ADMIN_MENU}' => $CURRENT_PIC_DATA['menu'],
        '{TITLE}' => bb_decode($CURRENT_PIC_DATA['title']),
        '{CAPTION}' => bb_decode($CURRENT_PIC_DATA['caption']),
        '{KEYWORDS}' => bb_decode($CURRENT_PIC_DATA['keywords']),
        '{USER}' => get_username($CURRENT_PIC_DATA['owner_id']),
        '{EXIF_STRING}' => $exif_string,
        );

You will of course have to modify the variable definition for $template_display_media accordingly.

Quote from: wuschel_lux on March 12, 2010, 02:11:41 PMMy problem here I can not insert a php "if" line to my code. Something like this:
$template_display_media = <<<EOT
<tr>
     ...
           if($exif['Model'] == "" || $exif['Focal length'] == "" || ...){echo "Equipment not available";} else {echo "Equipment: {MODEL} ({FOCALLENGTH}, {FNUMBER}, {EXPOSURETIME}, ISO {ISO})";}
     ...
</tr>
EOT;
Well, you could, provided you respected PHP coding rules. The following code would do the trick:$my_variable = <<<EOT
<h1>
EOT;
if ($foo == $bar) {
$my_variable .= <<<EOT
Hello World
EOT;
}
$my_variable .= <<<EOT
</h1>
EOT;
or (for shorter passages, not using the heredoc syntax):$my_variable = '<h1>';
if ($foo == $bar) {
$my_variable .= 'Hello World';
}
$my_variable .= '</h1>';

But after all, this is basic PHP skills, which is something which is beyond the scope of this board.

wuschel_lux

Thanks a lot for helping. I learned a lot about coppermine and PHP.

So the EXIF array is working fine but now I saw, when changing language for example english to german the output is "empty".
Reason the [Model] became [Modell] and so on, so $exif['Value'] doesn't work longer.

This change is realy harder than I thaught at the beginning. But the translation is near line 1000.

Αndré

Change $exif['Model'] to $exif[$lang_picinfo['Model']] and so on.

wuschel_lux

Excellent! Thank's, works now as I want to have it.

Many thanks to all for the support.