Cropping doesn't return right path to thumb directory


I’m trying to crop an Image that exists in a module called “event_info” (module plugin) but the cropping does not return the right path to the generated image in the thumb directory.

This is the path where the call to crop happens:


And this is the path where my picture files exists.


If I try to use something like this:

$speeches = $page->children()->visible();

<?php foreach ($speeches as $speech): ?>

    // get the module 'event-info' from $page
    <?php $event_info = $speech->find('event-info'); ?>

    <img src="<?php echo $event_info->event_image()->crop(300, 200, 80)->url() ?>" />

<?php endforeach ?>

Where $event_info is the $page object of the some_event/event-info module

this is what gets returned into the src attribute:

<img src="//localhost:8080/mypage/app/pic08.jpg" alt="">

Which is not the right path. What can I use here so I always get the appropriate thumb directory path?


edit: also the thumbnail doesn’t seem to get generated :confused:

I think you’re calling crop on a filename instead of on the actual file

Try this:

<?php echo $event_info->event_image()->toFile()->crop(300, 200, 80)->url() ?>

Note: I’d wrap the display of the img tag in a if statement to verify the image exists before trying to display it.

Thank you! That works.

For better understanding: When does a field return an image object and when a filename? ’ event_image() ’ is defined as an image field in the blueprint. I am using thumb() and focusCrop() on different points in my project and never had to use toFile().

Like I used this:

thumb($module->image($data->some_image_field()), array(...))

and that worked without using toFile()

Well the image() function is what transformed your filename into an image. You could also totally use it in the example above.

To make it simple, a field will always return plain text (or formatted YAML).

Kirby doesn’t know which field you used to enter the data. All it sees is text. You need to tell it that this text is an image.

Okay I see. So there is no hidden magic that automatically detects my field (from type image) as an image and not just a name ^^. Shame on me