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

Runtime config - add optional filter in main config #1277

Open
sabat24 opened this issue Apr 20, 2020 · 0 comments
Open

Runtime config - add optional filter in main config #1277

sabat24 opened this issue Apr 20, 2020 · 0 comments
Labels
Level: New Feature 🆕 This item involves the introduction of new functionality.

Comments

@sabat24
Copy link

sabat24 commented Apr 20, 2020

My use case. I have got a simple thumbnail filter:

basic_thumbnail:
            filters:
                thumbnail:
                    size:          [570, 380]
                    mode:          outbound
                    allow_upscale: true

I also allow my users to select the area of main image from which thumbnail will be generated. User can select an area respecting thumbnail ratio or ignore that possibility. In twig I generate thumbnails as follows:

{% set runtimeConfig = imageCropFilter %}
<img src="{{ asset(news, 'imageFile')|imagine_filter('basic_thumbnail', runtimeConfig) }}"

Problem with such option is that the new filter is merged to the original, which leads to situation where my additional crop filter is applied after creating of thumbnail, which is wrong (wrong in my use case to be clear).

I can change my config to something like that

basic_thumbnail:
            filters:
                crop: <--
                thumbnail:
                    size:          [570, 380]
                    mode:          outbound
                    allow_upscale: true

leaving crop filter empty. In this case merge will apply my runtime config in correct order. However in this case I will receive an exception from image/box.php constructor that width and heigh can't be empty.

I can resolve the problem by commenting out that line

throw new InvalidArgumentException(sprintf('Length of either side cannot be 0 or negative, current size is %sx%s', $width, $height));

and then adding following lines to crop method

if (empty($width) && empty($height)) {
     return $this;
}

Such approach allows me to create an optional crop filter, which will be ignored if no runtime config will be applied.

All in all I ask about a feature to set such optional filters out of the box to define order of filters which may be added later.

@dbu dbu added the Level: New Feature 🆕 This item involves the introduction of new functionality. label Oct 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Level: New Feature 🆕 This item involves the introduction of new functionality.
Projects
None yet
Development

No branches or pull requests

2 participants