Skip to content

Commit

Permalink
Apply glide params to src image (#252)
Browse files Browse the repository at this point in the history
* Apply glide params to src image

* Update snapshot
  • Loading branch information
aerni authored Oct 14, 2024
1 parent 87e4203 commit 70c5791
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/Tags/ResponsiveTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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')))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<img

src="/img/asset/dGVzdF9jb250YWluZXIvdGVzdC5qcGc=/test.jpg?w=340&amp;h=280"
src="/img/asset/dGVzdF9jb250YWluZXIvdGVzdC5qcGc=/test.jpg?blur=10&amp;w=340&amp;h=280"
alt="test.jpg"
width="340" height="280" data-statamic-responsive-images
>
Expand Down

0 comments on commit 70c5791

Please sign in to comment.