From 47c80e68a7ac9bb9461df0f438f4dc2ee2c11b98 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Wed, 8 May 2024 22:47:16 -0400 Subject: [PATCH] fix: Fixed an issue where the `.imgTag()` and `.pictureTag()` would output and invalid `style` attribute for lazy loaded images ([#400](https://github.com/nystudio107/craft-imageoptimize/issues/400)) --- src/models/BaseImageTag.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/models/BaseImageTag.php b/src/models/BaseImageTag.php index 175492ad..93906989 100644 --- a/src/models/BaseImageTag.php +++ b/src/models/BaseImageTag.php @@ -35,10 +35,11 @@ protected function swapLazyLoadAttrs(string $loading, string $placeHolder, array } // Set the style on this element to be the placeholder image as the background-image if (isset($attrs['style']) && !empty($attrs['src'])) { - $attrs['style'] = trim( - $attrs['style'] . - 'background-image:url(' . $this->getLazyLoadSrc($placeHolder) . '); background-size: cover;' - ); + if (empty($attrs['style'])) { + $attrs['style'] = []; + } + $attrs['style']['background-image'] = 'url(' . $this->getLazyLoadSrc($placeHolder) . ')'; + $attrs['style']['background-size'] = 'cover'; } // Handle attributes that lazy and lazySizesFallback have in common switch ($loading) {