I know there are a lot of questions on here about creating and using thumbnails. I looked through a bunch of them and I don’t think this one was asked.
On the thumb documentation page, it says “Creates a thumbnail for a given image object” But then below it says it can also return a $thumb or URL string. Does that mean that if the thumbnail with given parameters doesn’t exist, it’ll create it, else it’ll find and return the thumb image?
I ask because I noticed sometimes it creates new thumbnails and I wasn’t totally sure if I was using it right so i don’t want my code to make tons of random new thumbnails when I don’t need them.
A thumb of a given size, quality etc. for an image is only created once. If it already exists, it is not re-created, unless you delete the thumbs folder or rename the image.
What that means is the thumbs method returns either a string (the URL of the thumb) or an object, depending on whether the third parameter is set to true or false:
Example 1: Return an object
<?php
if($image = $page->images()->first()) {
dump (thumb($image, ['width' => 200], true)); // true is the default, so you don't have to set this, this is just to make it clearer
}