Problem/Motivation
In D7 the contrib module imagecache_actions defines the "Change file format" image effect (submodule imagecache_colorations). This effect is able to alter the output format (and quality setting when the ImageMagick toolkit is in use) of an image derivative. However, in D8 in its current state, this is no longer possible.
What is the difference between D7 and D8 causing this?
In D7 you could get and change the image info array and the save method of the toolkit would use this info array to determine the image format to save to. In D8 the info array has been split over individual protected properties that are publicly exposed by getters only.
Note: this issue is part of
#2105863: [meta] Images, toolkits and operations β
.
Proposed resolution
Instead of publicly exposing the info array or adding setters for the individual items in the info array, I suggest to add a saveOptions property or getSaveOptions() method to ImageInterfae. This property/method provides an alterable key-value store that can contain options that influence how an image is saved. Think of
- format (output as jpg, png or gif).
- quality for jpg.
- compression level and filters to use for png.
- progressive or not
- ...other?
This key-value store can be used by implementations of ImageToolkitInterface::save() to determine how to save the image.
The idea is that we change the API first with this additional property/method and then let toolkits decide what they accept, though we could (and should) document some keys that are foreseen (quality, format, compression, filter)
Why do it this way?
- This allows to fully utilize the abilities of the underlying toolkit, we are not restricting what parameters can be passed.
- It will make it easier to write a patch for issue
#1310452: Allow to override the image toolkit's global JPEG/PNG quality value β
(or it will allow us to do it in contrib, if we fail to get that one committed in a timely manner).
- Time: do this API change now, fill in new options later (not being API changes, the latter can be done after beta).
Remarks:
- The png filter is defined differently by different toolkits. The PNG_FILTER_XXX constants are defined by GD and not available when GD is disabled and thus cannot be used by our image system. So a set of own constants that the different toolkits have to map themselves should
be part of introducing that option.
- This patch will only introduce the format and quality options as they are necessary to remove the regression. and don't need UI changes.
- I propose to introduce compression and filter in
#1310452: Allow to override the image toolkit's global JPEG/PNG quality value β
as well as a UI (in image toolkit settings form) to define them.
- Setting to major as this is a regression from D7.
Remaining tasks
- review patch.
User interface changes
For now: none in the core UI.
API changes
Yes, but additions only.