Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Plugins

Present EXIF data of a photo

Started by Peter Berkel 5 years ago · 2 replies · 624 views
5 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

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

5 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 Rene, 1 week ago
2 47 1 week ago
Plugins · by Xavier, 4 weeks ago
2 56 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1182 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 50 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 74 2 months ago