Image styles have been converted from an array to an object that extends ConfigEntity. The following API changes happened as a result:
- All array keys are now properties on an ImageStyle object. ($style->effects
instead of $style['effects']
)
- The image_style_effects() function has been removed. Simply refer to $style->effects
instead.
- hook_image_styles_alter() has been removed.
- Because image styles are now entities, they implement all the same event hooks that entities do (presave, predelete, etc.)
Also, now all image styles provided by modules need to be defined as as YAML configuration files in the config/install folder of each module. As a consequence,
- 'thumbnail', 'medium' and 'large' image styles are defined in configuration files in the core/modules/system/config/install directory
hook_image_default_styles()
has been removedIMAGE_STORAGE_*
constants have been deprecated and will be removed before 9.0.x. There are no replacements given the concepts are different.
Providing image styles as configuration files (was in code in D7):
D7
function my_module_image_default_styles() {
$styles = array();
$styles['preview_big'] = array(
'label' => 'Big preview',
'effects' => array(
array(
'name' => 'image_scale',
'data' => array(
'width' => 600,
'height' => 600,
'upscale' => 1,
),
'weight' => 0,
),
array(
'name' => 'image_desaturate',
'data' => array(),
'weight' => 1,
),
),
);
return $styles;
}
D8
Suppose that your module is located at modules/my_module
, create a file modules/my_module/config/install/image.style.preview_big.yml
with the following content:
name: preview_big
label: 'Big preview'
effects:
eb6d5c40-26d1-11e3-8224-0800200c9a66:
id: image_scale
data:
width: '600'
height: '600'
upscale: '1'
weight: '0'
uuid: eb6d5c40-26d1-11e3-8224-0800200c9a66
2a4e0270-26d2-11e3-8224-0800200c9a66:
id: image_desaturate
data: { }
weight: '1'
uuid: 2a4e0270-26d2-11e3-8224-0800200c9a66
langcode: en
Note: You need to use a UUID generator to assign unique IDs to image style effects. Do not copy/paste UUIDs from other piece of code or from other image styles!