If I use the old method to create a thumbnail like this
$thumbnailObj = $imageHelper->getThumbnail($imgObj, 1200, 630, false);
How do I get the ID of that thumbnail? It doesn’t like this:
$thumbnailObjID = $thumbnailObj->getFileID();
If I use the old method to create a thumbnail like this
$thumbnailObj = $imageHelper->getThumbnail($imgObj, 1200, 630, false);
How do I get the ID of that thumbnail? It doesn’t like this:
$thumbnailObjID = $thumbnailObj->getFileID();
Try something like this
$thumbnailObj = $imageHelper->getThumbnail($imgObj, 1200, 630, false);
if ($thumbnailObj) {
$thumbnailPath = $thumbnailObj->src;
// Retrieve the file object based on the original image
$fileID = $imgObj->getFileID(); // This gets the original file ID
echo "Original File ID: " . $fileID;
echo "Thumbnail Path: " . $thumbnailPath;
} else {
echo "Thumbnail generation failed.";
}
Or
use Concrete\Core\File\Image\Thumbnail\Type\Type;
$thumbnailType = Type::getByHandle('large'); // Use a predefined thumbnail type
$thumbnailPath = $imgObj->getThumbnailURL($thumbnailType);
echo "Thumbnail URL: " . $thumbnailPath;
Thanks, but that’s not quite what I am trying to do. What I need is the ID of the thumbnail I have just created, so I can then save it as the Thumbnail Attribute of the page.
Thumbnail is confusingly used in 2 contexts.
The page thumbnail (1) is what you select for the page attribute. Its then up to the themes and block templates using the thumbnail attribute (1 - which is an fID) to decide how to present that using the image, or a specific thumbnail (2) of the image as per @TMDesigns notes.
Yes, basically I am trying to go from context 2 to context 1.
I need to:
So perhaps, I need to create a file based on getThumbnail method, then I can save that using setAttribute?
Yeah it is possible.
You would have to generate thumbnail → import to to File Manager → set new page attribute.
Though, is it really what you need?
You have already two system available in Concrete that do exactly the same, without any hassle:
a) Image helper (custom dimensions)
b) Thumbnail system (predefined dimensions)
You can display/download those images etc.
Unless, for some reason, you really need to swap original image.