Kirby 2.3 - Real strange thumbnail problem

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

github.com/getkirby/kirby/issues/415

I have encountered a similar problem and opened an github issue https://github.com/getkirby/kirby/issues/414.

1 Like

I’m not sure if your problem is the same as mine but I have lots of problems with the thumbnails right now. I’ve added 3 or 4 threads here. Maybe should have reported them as bugs on Github, but because I don’t fully understand how the generation works, I’m not sure what’s bugs and what’s just a change of syntax.

If I don’t get any solutions here, I will probably report them as bugs later anyway.

I think, it’s the same issue, because the first thumb url does not get returned correctly somehow.
But you are right, there are several things left to be fixed with the new thumb API.

@jenstornell: It makes more sense to create an issue on Github instead of opening multiple related threads here, I think.

Yeah, I felt a little spammy. I added them there as well. Will try to do a better judgement next time.