1 image.api.php hook_image_styles_alter(&$styles)

Modify any image styles provided by other modules or the user.

This hook allows modules to modify, add, or remove image styles. This may be useful to modify default styles provided by other modules or enforce that a specific effect is always enabled on a style. Note that modifications to these styles may negatively affect the user experience, such as if an effect is added to a style through this hook, the user may attempt to remove the effect but it will be immediately be re-added.

The best use of this hook is usually to modify default styles, which are not editable by the user until they are overridden, so such interface contradictions will not occur. This hook can target default (or user) styles by checking the $style['storage'] property.

If your module needs to provide a new style (rather than modify an existing one) place the whole config file in your modules /config directory instead.

Related topics

File

core/modules/image/image.api.php, line 139
Hooks related to image styles and effects.

Code

function hook_image_styles_alter(&$styles) {
  // Check that we only affect a default style.
  if ($styles['thumbnail']['storage'] == IMAGE_STORAGE_DEFAULT) {
    // Add an additional effect to the thumbnail style.
    $styles['thumbnail']['effects'][] = array(
      'name' => 'image_desaturate',
      'data' => array(),
      'weight' => 1,
      'effect callback' => 'image_desaturate_effect',
    );
  }
}