Thumb function implementation


#1

On https://getkirby.com/docs/templates/thumbnails I found the nice idea of a thumb creation.

Unfortunately there is no statement on how to implement the phrase echo thumb($page->image(‘cover.jpg’), array(‘width’ => 300)); into the html code.

Has anyone an idea?

Cheers, Daniel


#2

The command you quote create an image tag automatically, no reason to implement that in the HTML code. If you want to use an image tag, you would do it like this:

<?php
$image = $page->image('cover.jpg');
if($image) : ?>
<img src="<?= thumb($image, array('width' => 300))->url() ?>">
<?php endif ?>

Instead of using the thumb helper, you can also use the resize method:

<?php
$image = $page->image('cover.jpg');
if($image) : ?>
<img src="<?= $image->resize(300)->url() ?>">
<?php endif ?>