Loading Image Thumbnail

I am loading a custom image attribute in a template. I like to load the attribute and assign a custom thumbnail ( Dashboard > System > Files> Thumbnails) to the image.

Now I have several way to load the image attribute. My Questions:
- How do I load the thumbnail (named: small).
- What is the best way to load the image attribute (see example: blogimage)

<?php if($c->getAttribute('blogimage')){
    echo '<img src="' . $c->getAttribute('blogimage')->getVersion()->getRelativePath() . '"/>';}

    $img = $c->getAttribute('blogimage'); ?>
    <?php if ($img): ?>
    <img src="<?php  echo ($img->getVersion()->getRelativePath()); ?>"/>
<?php endif; ?>

<img src="<?php $c = Page::getCurrentPage(); echo ($c->getAttribute('blogimage')->getVersion()->getRelativePath());?>">

View Replies: View Best Answer
simpit replied on at Permalink Best Answer Reply

Your second attempt is slightly better, because access the database only once ($img =...). Your third approach will raise an error if no image is set (getVersion() on null)

Working with thumbnails:

First get your Thumbnail Type:
$thumbnail_type = \Concrete\Core\File\Image\Thumbnail\Type\Type::getByHandle('small');

Then you can get the blog image source url:
$src = $img->getThumbnailURL($thumbnail_type->getBaseVersion());

For more details, see the official documentation:https://documentation.concrete5.org/developers/working-with-files-an...
studio4graphics replied on at Permalink Reply
Thank you for explaining.

Also asked the Question on Stack Overflow (https://stackoverflow.com/questions/51206234/loading-thumbnail-of-a-page-image-attribute-in-concrete5)

So now I am using
$img = $c->getAttribute('blogimage');
if ($img !== null) {
    $imgVersion = $img->getVersion();
    $thumbnailURL = $imgVersion->getThumbnailURL('small');
    ?><img src="<?= $thumbnailURL ?>" /><?php