-
|
Hi, we're using the following config in craft v5: // config/imager-x-generate.php
return [
'volumes' => [
'uploads' => [
'standardImageTransformsWebp'
],
]// config/imager-x-transforms.php
return [
'standardImageTransformsWebp' => [
'defaults' => [
'format' => 'webp',
'webpQuality' => 80
],
'transforms' => [
['width' => 480],
['width' => 960],
['width' => 1920]
]
]
];We now want to retrieve just the image urls for the optimized images. According to https://imager-x.spacecat.ninja/usage/php.html, something like this can be used: $imagerx = Craft::$app->plugins->getPlugin('imager-x');
$thumbSrcset = '';
if ($imagerx && $imagerx instanceof \spacecatninja\imagerx\ImagerX) {
$heroImage = $entry->image->one();
$transforms = $imagerx->imager->transformImage($heroImage, 'listThumbnail');
$thumbSrcset = $imagerx->imager->srcset($transforms);
}I just wanted to make sure and ask: Does I would love to avoid the case that the image is optimized/processed each time I use this function in a API project. I just want to return the URLs for 480, 960, 1920 in my REST API project (Craft CMS). Image optimization should only happen when editors upload the image into the CMS, not on api calls. Thanks very much in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
If the image has been transformed (and the Imager cache hasn't been deleted later), the code will not result in additional transforms. The check for if the transform exists is inside the Hope that answers your question? |
Beta Was this translation helpful? Give feedback.
If the image has been transformed (and the Imager cache hasn't been deleted later), the code will not result in additional transforms. The check for if the transform exists is inside the
transformImagemethod, so it'll work exactly the same via both PHP and Twig.Hope that answers your question?