hook_image_styles_alter

  1. drupal
    1. 8
    2. 7
Versions
7 – 8 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) use hook_image_default_styles() instead.

See also

hook_image_default_styles()

Related topics

Code

modules/image/image.api.php, line 136

<?php
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',
    );
  }
}
?>