Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Controller/RuntimeAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __invoke(Request $request, string $hash, string $path, string $f
throw new BadRequestHttpException(\sprintf('Signed url does not pass the sign check for path "%s" and filter "%s" and runtime config %s', $path, $filter, \json_encode($config)));
}

return $this->processAndRespond($this->filterService, $path, $filter, $config, resolver: $resolver);
return $this->processAndRespond($this->filterService, $path, $filter, ['processors' => $config], resolver: $resolver);
}

/**
Expand Down
13 changes: 9 additions & 4 deletions src/Imagine/Cache/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ public function generateUrl(string $path, string $filter, array $config, ?string
$params['resolver'] = $resolver;
}

$params['processors'] = $config;
$params['hash'] = $this->signer->sign($path, $this->getFilterSecret($filter), $config);
/** @var array<string, mixed> $processors */
$processors = $config['processors'] ?? $config;
$params['processors'] = $processors;
$params['hash'] = $this->signer->sign($path, $this->getFilterSecret($filter), $processors);

return $this->router->generate('_chamber_orchestra_image', $params, $referenceType);
}
Expand Down Expand Up @@ -155,8 +157,11 @@ public function remove(string $path): void
*/
private function extractDensity(array $config): int
{
foreach ($config as $key => $value) {
if ('output' !== $key && \is_array($value) && \is_numeric($value['density'] ?? null)) {
/** @var array<string, mixed> $processors */
$processors = $config['processors'] ?? $config;

foreach ($processors as $value) {
if (\is_array($value) && \is_numeric($value['density'] ?? null)) {
return (int) $value['density'];
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/Resources/views/macro/image.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
{%- endmacro -%}

{%- macro fit(src, width, height, attr, picture_attr = {}) -%}
{# add support of ChamberOrchestra\FileBundle\Model\File — use relativePath for image filters, falls back to uri #}
{%- set src = src.relativePath|default(src.uri|default(src)) -%}
{# add support of ChamberOrchestra\FileBundle\Model\File #}
{%- set src = src.uri|default(src) -%}
{%- set attr = attr|default({})|merge({width: attr.width|default(width), height: attr.height|default(height), style: 'height: auto', loading: 'lazy', decoding: 'async'}) -%}
<picture {{ _self.attributes(picture_attr) -}}>
<source {#
Expand All @@ -36,8 +36,8 @@
{%- endmacro -%}

{%- macro fill(src, width, height, attr, picture_attr = {}) -%}
{# add support of ChamberOrchestra\FileBundle\Model\File — use relativePath for image filters, falls back to uri #}
{%- set src = src.relativePath|default(src.uri|default(src)) -%}
{# add support of ChamberOrchestra\FileBundle\Model\File #}
{%- set src = src.uri|default(src) -%}
{%- set attr = attr|default({})|merge({width: attr.width|default(width), height: attr.height|default(height), style: 'height: auto', loading: 'lazy', decoding: 'async'}) -%}

<picture {{ _self.attributes(picture_attr) -}}>
Expand All @@ -61,8 +61,8 @@

{%- macro css_fit(src, width, height, use2x = true) -%}

{# add support of ChamberOrchestra\FileBundle\Model\File — use relativePath for image filters, falls back to uri #}
{%- set src = src.relativePath|default(src.uri|default(src)) -%}
{# add support of ChamberOrchestra\FileBundle\Model\File #}
{%- set src = src.uri|default(src) -%}
{%- set url = (src|default('')|fit(width, height)) -%}
{%- set webp = (src|default('')|fit(width, height, {output: {format: 'webp'}})) -%}
{%- set avif = (src|default('')|fit(width, height, {output: {format: 'avif'}})) -%}
Expand Down Expand Up @@ -104,8 +104,8 @@

{%- macro css_fill(src, width, height, use2x = true) -%}

{# add support of ChamberOrchestra\FileBundle\Model\File — use relativePath for image filters, falls back to uri #}
{%- set src = src.relativePath|default(src.uri|default(src)) -%}
{# add support of ChamberOrchestra\FileBundle\Model\File #}
{%- set src = src.uri|default(src) -%}

{%- set url = (src|default('')|fill(width, height)) -%}
{%- set webp = (src|default('')|fill(width, height, {output: {format: 'webp'}})) -%}
Expand Down