Skip to content

Commit

Permalink
fix: Don't add image variants if no variant creator for them exists ([#…
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Oct 9, 2024
1 parent 1b26260 commit ab772d0
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/services/OptimizedImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ab772d0

Please sign in to comment.