Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Template modifications - add some EXIF data near the intermediate image  (Read 11552 times)

0 Members and 1 Guest are viewing this topic.

wuschel_lux

  • Translator
  • Coppermine regular visitor
  • **
  • Offline Offline
  • Gender: Male
  • Posts: 93
    • volleyball.lu - photo gallery & shop

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
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764

From displayimage.php:
Code: [Select]
   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.
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de

Do a
Code: [Select]
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.
Logged

wuschel_lux

  • Translator
  • Coppermine regular visitor
  • **
  • Offline Offline
  • Gender: Male
  • Posts: 93
    • volleyball.lu - photo gallery & shop

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

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

I Found this in the doc:
Code: [Select]
print <<< EOT
<h1>Hello {$bla}</h1>
EOT;
}
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764

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.


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

Code: [Select]
$template_display_media = <<<EOT
 <tr>
     ...
          EXIF Info: {???}
     ...
 </tr>
EOT;
You mustn't add it there. Just add it below
Code: [Select]
$info = array_merge($info, $exif);
Logged

wuschel_lux

  • Translator
  • Coppermine regular visitor
  • **
  • Offline Offline
  • Gender: Male
  • Posts: 93
    • volleyball.lu - photo gallery & shop

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
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764

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
Code: [Select]
    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
Code: [Select]
    $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']),
Logged

wuschel_lux

  • Translator
  • Coppermine regular visitor
  • **
  • Offline Offline
  • Gender: Male
  • Posts: 93
    • volleyball.lu - photo gallery & shop

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  :(
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764

I have no output on the screen  :(
don't forget that you may have to change the scope using the global command.
Logged

wuschel_lux

  • Translator
  • Coppermine regular visitor
  • **
  • Offline Offline
  • Gender: Male
  • Posts: 93
    • volleyball.lu - photo gallery & shop

I added the line
Code: [Select]
global $metadata_path, $exif;already before, but no output.

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

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: Template modifications - add some EXIF data near the intermediate image
« Reply #10 on: March 12, 2010, 01:09:37 pm »

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

This code works (global is not necessary):
Code: [Select]
    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);
    }
Logged

wuschel_lux

  • Translator
  • Coppermine regular visitor
  • **
  • Offline Offline
  • Gender: Male
  • Posts: 93
    • volleyball.lu - photo gallery & shop
Re: Template modifications - add some EXIF data near the intermediate image
« Reply #11 on: March 12, 2010, 01:16:49 pm »

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.
Logged

wuschel_lux

  • Translator
  • Coppermine regular visitor
  • **
  • Offline Offline
  • Gender: Male
  • Posts: 93
    • volleyball.lu - photo gallery & shop
Re: Template modifications - add some EXIF data near the intermediate image
« Reply #12 on: March 12, 2010, 02:11:41 pm »

so with adding following lines I got the expected result based on the array in the post before:
Code: [Select]
'{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:
Code: [Select]
$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;
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Template modifications - add some EXIF data near the intermediate image
« Reply #13 on: March 12, 2010, 02:31:32 pm »

Well, I can't see the point in populating so many placeholder tokens anyway - just populating one string will do the trick:
Code: [Select]
$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.

My problem here I can not insert a php "if" line to my code. Something like this:
Code: [Select]
$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:
Code: [Select]
$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):
Code: [Select]
$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.
« Last Edit: March 12, 2010, 02:39:08 pm by Joachim Müller »
Logged

wuschel_lux

  • Translator
  • Coppermine regular visitor
  • **
  • Offline Offline
  • Gender: Male
  • Posts: 93
    • volleyball.lu - photo gallery & shop
Re: Template modifications - add some EXIF data near the intermediate image
« Reply #14 on: March 12, 2010, 03:40:48 pm »

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.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: Template modifications - add some EXIF data near the intermediate image
« Reply #15 on: March 12, 2010, 03:52:42 pm »

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

wuschel_lux

  • Translator
  • Coppermine regular visitor
  • **
  • Offline Offline
  • Gender: Male
  • Posts: 93
    • volleyball.lu - photo gallery & shop
Re: Template modifications - add some EXIF data near the intermediate image
« Reply #16 on: March 15, 2010, 07:53:56 am »

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

Many thanks to all for the support.
Logged
Pages: [1]   Go Up
 

Page created in 0.031 seconds with 20 queries.