This isn’t a question exactly, more an observation and what I might do about it.
I use a function in a controller that pulls the value of an ‘articleimage’ field and either resizes it or crops it via the focus crop plugin.
However I just used it and specified dimensions that are identical to the source image. The quirk is this - it generated a thumbnail! I was expecting it to realise the dimensions where identical to the source image and spit out the URL to the source rather then resizing it. I know kirby is clever, perhaps I assume to much
My function looks like this:
function poster($page, $mode, $width, $height, $class, $fixed = false) {
if($articleimgsrc = $page->articleimage()->toFile()) {
if ($mode == 'resize') {
$thumb = $articleimgsrc->resize($width);
}
if ($mode == 'crop') {
$thumb = $articleimgsrc->focusCrop($width, $height);
}
$articleimage = brick('img');
$articleimage->attr('src', $thumb->url());
if ($fixed == true) {
$articleimage->attr('width', $thumb->width().'px');
$articleimage->attr('height', $thumb->height().'px');
}
$articleimage->attr('alt', $articleimgsrc->alt());
$articleimage->attr('style', 'max-width:'.$width.'px');
$articleimage->addClass($class);
} else {
$articleimage = brick('p', 'Article Image Not Set');
}
return $articleimage;
}
And i used it in my template like this:
<figure class="product-thumb">
<?= poster($page, 'resize', 175, 150, 'articleimage', false) ?>
</figure>
Whats the simplest way to check the source images dimensions and only resize or focus crop if they are not exactly equal? I do feel like the resize function should handle this on its own though, since its a wasted process.