Problem/Motivation
At the moment it is possible to set/getThirdPartySettings on the image style, but the effects that are part of that style do not have any visibility on them. There are use cases where a setting at the ImageStyle level should be accessed by its ImageEffects. Also, there are cases where one effect in the sequence needs to hand over some setting to an effect coming later in the sequence.
Examples:
- In a
ImageStyle::transformDimensions()
call, an effect determines dimensions based on Exif rotation information, reading the info from the file via the $uri parameter. That effect should 'flag' that autorotation has been performed already, because since the Exif metadata is not updated back to the source file, if another instance of the same effect is present in the effect collection, it will change again the dimensions. So that 'flag' would prevent the second effect instance to execute. - #204497: Configurable background color when cropping to larger dimensions, and in particular comment #204497-82: Configurable background color when cropping to larger dimensions
- Textimage sets a TPS in the ImageStyle, being the 'background color' of the image. That is used by 'Textimage text' effects part of the style to deal with cases where the image needs to extended in size, so that the color used to fill in the extended part of the image be consistent across all the effects. Also see #2098247: Provide a hook for ImageStyle::createDerivative.
Proposed resolution
Introduce an ImageEffectWithRuntimeVariablesInterface and trait so that effects that need to access the parent ImageStyle can do so, and can also set arbitary 'runtime variables' that can be accessed by further effects, and whose scope is limited within the execution of a ImageStyle::createDerivative, ::transformDimensions, or ::getDerivativeExtension call. Change the ImageEffectPluginCollection so to inject the runtime variables and the image style id to relevant effect plugins on initialization.
Remaining tasks
User interface changes
None.
API changes
Introduce a new ImageEffectWithRuntimeVariablesInterface with relevant methods.
Beta phase evaluation
Issue category | Feature request because provides visibility of ImageStyle to its ImageEffects so that effects can access style's third party settings. |
---|---|
Issue priority | Normal because this is only to allow contrib to leverage the image style third party settings interface. |
Prioritized changes | The main goal of this issue is expanding capabilities of the ImageStyle/ImageEffects system, allowing contrib to leverage the image style third party settings interface. |
Disruption | Not disruptive, will just allow contrib to leverage the image style third party settings interface, no changes to core effects. |
Original report by @zuuperman
There are some use cases for effects, that require the style information to be given as argument to the effect callbacks. This is mostly the case when the effect settings can change per file.
For example: http://drupal.org/node/1250506#comment-4889248
The same goes for dimension callbacks, but i will update this in #1364670: ImageStyle::transformDimensions unable to deal with all effects.