Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Present EXIF data of a photo

Started by Peter Berkel 6 years ago · 2 replies · 1017 views
6 years ago

I want to make a page where I can present de EXIF data of a photo.
Therefore a tried to make a plugin according to the plugin recipe. https://learn.getgrav.org/17/cookbook/plugin-recipes.

I left the example.php unchanged.
I adjusted the ExampleTwigExtension.php. in particular the public function exampleFunction()

PHP
public function exampleFunction()
    {
        $image_file = 'test.jpeg'
        $exif = exif_read_data($image_file, 0, true);
        foreach ($exif as $key => $section) {
          foreach ($section as $name => $val) {
            echo "$key.$name: $val \n";
          }
        }
       return;
    }

In the pageheader I set:
process:
twig: true
In the page I use {{ example() }} to present the EXIF data. This is however the intention.

I am almost certain that the php code is incorrect. I don't know exactly which one should be. Can anyone help me?
Thank you.
Peter

6 years ago

Did you check what exif_read_data() returns? I'd bet it's false, because it can't find 'test.jpeg'. Also your PHP code should end up in Fatal syntax error, because $image_file = 'test.jpeg' is missing semicolon at the end.

6 years ago

Thanks for answering. Found the solution.
First the path to the file was indeed wrong. Second the name of the plugin and the names of the php and yaml file were different. Third I found an error in the example.php file which is presented in the learn environment (plugin-recipes).
Line 14: require_once(DIR . '/twig/ExampleTwigExtension.php’); should be: require_once(DIR . '/ExampleTwigExtension.php’);
Last I got all the information in one line. I tried something with \n. But this did not work. <br> worked however.

Suggested topics

Topic Participants Replies Views Activity
Plugins · by DrPen, 3 weeks ago
2 289 3 weeks ago
Plugins · by renedebaaij, 4 weeks ago
1 263 3 weeks ago
Plugins · by Thomas, 4 weeks ago
1 280 4 weeks ago
Plugins · by complanar, 2 months ago
6 600 1 month ago
Plugins · by BenLaKnet, 1 month ago
1 504 1 month ago