Creating thumbnails from page image attribute in single page controller

Permalink 1 user found helpful
Hi,

I'm putting a Page list into a single page controller, using Concrete 8.5.1.

What is the correct/best way to create thumbnails from a page image attribute in this instance?

So far I have tried all sorts with no joy - but from what I can see, this *should* work..

$thumbnail = $p->getAttribute('page_thumbnail');
$img = Core::make('html/image', array($thumbnail));
$image = $img->getTag();
echo $image;


This gives me the following error:

Class 'Application\Controller\SinglePage\Core' not found

==========

I'm presuming there is a different way to do this in single pages - but I can't find anything in the docs/forums that works.

Can anyone point me in the right direction please?

Thanks.

drbiskit
 
hutman replied on at Permalink Reply
hutman
You should be able to change it to

$img = $this->app->make('html/image', array($thumbnail));


or add

use \Core;


to the top of the controller.
drbiskit replied on at Permalink Reply
drbiskit
Hi - Thanks for the response.

Changing:
$img = Core::make('html/image', array($thumbnail));

to:
$img = $this->app->make('html/image', array($thumbnail));

Means that I get the path to the original uploaded file, rather than a new cached version of the image which is what I'm after.
hutman replied on at Permalink Reply
hutman
That code is exactly the same, it just doesn't throw the error because you're not using Core without defining it.
drbiskit replied on at Permalink Reply
drbiskit
Thanks. Do you know how to output a thumbnail from this?
hutman replied on at Permalink Best Answer Reply
hutman
Here is the documentation for the "old" way to output a thumbnail and the "new" way

https://documentation.concrete5.org/developers/working-with-files-an...
drbiskit replied on at Permalink Reply
drbiskit
Thanks that was helpful.

For anyone coming up against the same issue - follow the instructions on this link below about creating new thumbnail types:
https://documentation.concrete5.org/developers/working-with-files-an...

Then in the page list foreach loop:

$type = \Concrete\Core\File\Image\Thumbnail\Type\Type::getByHandle('page');
$thumbnail = $c->getAttribute('page_thumbnail');
if (is_object($thumbnail)) {
  $src = $thumbnail->getThumbnailURL($type->getBaseVersion());
}
echo $src