From 5a1589cb7e3531a3a2e11a5a19b678a0fdb0cc0a Mon Sep 17 00:00:00 2001 From: Michael Aerni Date: Wed, 9 Oct 2024 15:34:53 -0400 Subject: [PATCH] Apply glide params to src image --- src/Tags/ResponsiveTag.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Tags/ResponsiveTag.php b/src/Tags/ResponsiveTag.php index 4aae72c..269cef4 100644 --- a/src/Tags/ResponsiveTag.php +++ b/src/Tags/ResponsiveTag.php @@ -59,10 +59,10 @@ public function index() $width = $dimensions->getWidth(); $height = $dimensions->getHeight(); - $src = app(GenerateImageJob::class, ['asset' => $responsive->asset, 'params' => [ - 'width' => $width, - 'height' => $height, - ]])->handle(); + $src = app(GenerateImageJob::class, [ + 'asset' => $responsive->asset, + 'params' => array_merge($this->getGlideParams(), ['width' => $width, 'height' => $height]), + ])->handle(); $includePlaceholder = $this->includePlaceholder(); @@ -82,6 +82,14 @@ public function index() ])->render(); } + private function getGlideParams(): array + { + return collect($this->params) + ->reject(fn ($value, $name) => ! str_starts_with($name, 'glide:')) + ->mapWithKeys(fn ($value, $name) => [str_replace('glide:', '', $name) => $value]) + ->toArray(); + } + private function getAttributeString(): string { $breakpointPrefixes = collect(array_keys(config('statamic.responsive-images.breakpoints')))