Get ID of thumbnail

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.

  1. A page thumbnail, selected as the image fID.
  2. Thumbnails as in a particular resize and crop of an image

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:

  1. Get the original pages “thumbnail” attribute
  2. Resize to 1200 x 630 pixels
  3. Save as the new pages “thumbnail” attribute.

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.