diff --git a/README.md b/README.md index 0d3b752..d373496 100644 --- a/README.md +++ b/README.md @@ -345,6 +345,7 @@ or |`lqip`|`boolean`|See config|Use LQIP| |`sizes`|`string`| |The image sizes attributes| |`width`|`int`|`1000`|Used with `layout` `constrained` and `fixed`| +|`imageStyles`|`array`|`[]`|Apply styles to placeholder and main `img` tags (ex.: `[['object-fit' => 'contain']]`| #### Examples diff --git a/src/ViewModels/ImageViewModel.php b/src/ViewModels/ImageViewModel.php index 3e1b7b9..8a6d987 100644 --- a/src/ViewModels/ImageViewModel.php +++ b/src/ViewModels/ImageViewModel.php @@ -89,6 +89,11 @@ class ImageViewModel extends ViewModel implements Arrayable */ protected $width; + /** + * @var int $imageStyles Styles applied to the placeholder and main img tag + */ + protected $imageStyles; + /** * @var ImageStyles */ @@ -123,7 +128,8 @@ public function __construct($data, $overrides = []) $this->layout, $this->backgroundColor, $this->width, - $this->height + $this->height, + $this->imageStyles ); } @@ -162,6 +168,10 @@ protected function setAttributes($overrides) $this->width = $overrides['width'] ?? null; $this->height = $overrides['height'] ?? null; + + $this->imageStyles + = $overrides['imageStyles'] + ?? []; } /**