I’m not totally sure if this is a bug but it’s a really strange behaviour anyway.
This is what comes out of Kirby 2.3. The image is displaying in full resolution instead of a thumbnail. It should be a thumbnail icon here.
When I echo $image->url() before running the thumb function it works.
I copy paste some code from my template:
Maybe much code but I don’t want to mess too much with this site. Look for “// THIS DOES THE MAGIC” in the controller.
This code will not work out of the box. Everything is not in there. Mainly for reading.
<?php if( ! empty( $events ) ) :
$i = 1;
$count = ( ! empty( $count ) ) ? $count : 30;
?>
<ul>
<?php foreach( $events as $item ) : ?>
<?php if( $count >= $i ) : ?>
<li<?php echo $item->list_class; ?>>
<a href="<?php echo $item->url; ?>/">
<?php if( ! empty( $item->thumb_url ) ) : ?>
<figure>
<img src="<?php echo $item->thumb_url; ?>">
</figure>
<?php endif; ?>
<div class="content-group">
<div class="date"><?php echo $item->event_modified; ?></div>
<div class="title"><?php echo $item->event_title; ?></div>
<div class="excerpt"><?php echo $item->event_excerpt; ?></div>
</div>
</a>
</li>
<?php endif; ?>
<?php
$i++;
endforeach; ?>
</ul>
<?php endif; ?>
From my controller:
<?php
return function($site, $pages, $page, $template) {
return array(
'map' => script(),
'events' => events($page),
'sidebar' => 'events',
);
};
function events($page) {
$pages = page('aktiviteter/evenemang')->children()->limit(2);
foreach( $pages as $i => $item ) {
$array[$i]['url'] = $item->url();
$array[$i]['list_class'] = ( $item->isOpen() ) ? ' class="active"' : '';
$array[$i]['event_title'] = $item->title()->value();
$array[$i]['event_excerpt'] = excerpt( $item->text()->value(), 100 );
$array[$i]['event_modified'] = $item->modified('Y-m-d');
if( ! empty( (string)$item->icon() ) ) {
if( $item->image( $item->icon() ) ) {
$image = $item->image( $item->icon() );
echo $image->url(); // THIS DOES THE MAGIC
$thumb = thumb(
$image,
array(
'width' => 120,
'height' => 120,
'crop' => true
)
);
$array[$i]['thumb_url'] = $thumb->url();
}
}
}
if( ! empty( $array) ) {
$object = json_decode(json_encode($array), FALSE);
return $object;
}
}
Why it works only when I echo the $image->url() before I do something else is a mystery to me. I tried to echo other stuff but it did not make any difference so something is strange with that function.
When I remove the echo $image->url(); the large image is shown again.
Update
Added to github