function hook_image_styles_alter

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

1 invocation of hook_image_styles_alter()
image_styles in drupal/modules/image/image.module
Gets an array of all styles and their settings.

File

drupal/modules/image/image.api.php, line 142
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',
    );
  }
}