diff --git a/src/services/OptimizedImages.php b/src/services/OptimizedImages.php index b442cc6..706dd6b 100644 --- a/src/services/OptimizedImages.php +++ b/src/services/OptimizedImages.php @@ -566,8 +566,24 @@ protected function addVariantImageToModel(Asset $asset, OptimizedImage $model, $ $asset, $transform ); + // Only add the variant URLs if a creator for them exists + /** @var Settings $settings */ + $settings = ImageOptimize::$plugin->getSettings(); + $activeImageVariantCreators = $settings->activeImageVariantCreators; + try { + $fileFormat = $asset->getFormat(); + } catch (Throwable $e) { + $fileFormat = ''; + } + $fileFormat = strtolower($fileFormat); + // Special-case for 'jpeg' + if ($fileFormat === 'jpeg') { + $fileFormat = 'jpg'; + } + if (!empty($activeImageVariantCreators[$fileFormat])) { + $model->optimizedWebPImageUrls[$transform->width] = $webPUrl; + } //ImageOptimize::$plugin->transformMethod->prefetchRemoteFile($webPUrl); - $model->optimizedWebPImageUrls[$transform->width] = $webPUrl; $model->focalPoint = $asset->focalPoint; $model->originalImageWidth = $asset->width; $model->originalImageHeight = $asset->height;