Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/allow imgproxy url modification #11

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions Classes/Aspects/ThumbnailAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ public function generateImgproxyUri(JoinPointInterface $joinPoint): ?array

$expectedSize = ImgproxyBuilder::expectedSize($actualDimension, $targetDimension, $resizingType, $enlarge);

foreach ($this->settings['imgproxyUrlModifiers'] as $modifierClassName){
if(class_exists($modifierClassName)){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO class_exists() and is_callable() should be removed here. When class does not exist or isn't callable, then i prefer to get an Exception and to know i made a mistake.

$modifier = new $modifierClassName();
if(is_callable($modifier)){
$modifier($url, $configuration);
}
}
}

return [
'width' => $expectedSize->getWidth(),
'height' => $expectedSize->getHeight(),
Expand Down
5 changes: 5 additions & 0 deletions Classes/ImgproxyUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@ public function cacheBuster(string $cacheBuster)
{
$this->processingOptions[] = 'cb:' . $cacheBuster;
}

public function addProcessingOption($key, $value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$key can be type-hinted with string

{
$this->processingOptions[] = $key . ':' . $value;
}
}
3 changes: 3 additions & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Networkteam:
# Let imgproxy choose the file extension based on client preferences
autoFormat: true

# This allows to modify the imgproxy url before it gets returned
imgproxyUrlModifiers: []

# Format Quality, eg: 'jpg:75:avif:80:webp:70'
formatQuality: ''

Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,25 @@ docker run -p 8080:8080 -it \
* Neos will **not generate any thumbnail**, they are generated ad-hoc from imgproxy as soon as a client requests it.

Note: make sure to add a caching proxy / CDN on top of imgproxy, it has no built-in caching!

## How to modify the imgproxy url
If you need to modify the imgproxy url for your custom needs you can use the following hook:
1. Create a modifier class in this format:
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add php here and <?php in the next line

namespace Foo\Bar;

class ModifierClass
{
public function __invoke(ImgproxyUrl $url, ThumbnailConfiguration $configuration): void
{
// modify the ImgproxyUrl object
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add call to the new function here? $url->addProcessingOption('auto_rotate', 1)

}
}
```
2. Register your modifier in the settings:
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add yaml here

Networkteam:
ImageProxy:
imgproxyUrlModifiers:
- Foo\Bar\ModifierClass
```