How do you use a pre-generated thumbnail (not automatically generated) as, say a link to a bigger image in K2.
For example I have an image ‘big-image.jpg’ and a thumb ‘big-image.thumb.jpg’.
Previously I’d have used the thumb plugin… with something like:
<?php foreach($images as $image)?>
<figure>
<a href="<?php echo $image->url() ?>">
<img src="<?php echo $image->thumb()->url()?>"/>
</a>
</figure>
<?php endforeach ?>
Hi,
it’s built in: thumb()
for your example:
<?php foreach($images as $image)?>
<figure>
<a href="<?php echo $image->url() ?>">
<? echo thumb($image, array('width' => 400, 'height' => 400, 'crop' => true)) ?>
</a>
</figure>
<?php endforeach ?>
/edit: please check if there is a folder named thumbs
in your Kirby root. Just create one if it isn’t there.
Thanks for your reply andi242, but perhaps I wasn’t being clear enough as that was not quite what I was asking for.
We create our own thumbs… you used to able to use them rather than have Kirby generate them, which is what you are suggesting I think?
So we want to use pre-made (by us) thumbs existing in the same content folder as the large images.
‘big-image.jpg’ and a thumb ‘big-image.thumb.jpg’.
I hope that is more clear?
You could use $image->filterBy
: http://getkirby.com/docs/cheatsheet/files/filterBy
For example (untested, just a quick idea):
<?php foreach($page->images()->filterBy('filename', '*=', '.thumb') as $image)?>
<figure>
<a href="<?php echo $page->image(str_replace('.thumb', '', $image->name())->url() ?>">
<img src="<?php echo $image->url()?>"/>
</a>
</figure>
<?php endforeach ?>
Thanks distantnative, yeah we’d already been using similar code to get round this.
<?php foreach(($page->images()->filterBy('filename','*=',"-thumb")) as $image ): ?>
<figure>
<a href="<?php echo str_replace('-thumb', '', $image->url()) ?>">
<img src="<?php echo $image->url()?>"/>
</a>
<figcaption>
<?php echo $image->name()?>
</figcaption>
</figure>
<?php endforeach ?>
But I thought there might be a better way to do it…
Also we have many, many images in the format xxx.thumb.png
for the thumbnail and xxx.png
for the big image.
Sadly when we came to look at a workaround for our problem using the filterby()
and file names we noticed ‘xxx.thumb.png’ would not work, where as ‘xxx-thumb.png’ does. Not sure if there is a fix for this… or a bug?