Example for hook_image_styles_alter().

Public

Update the core's image styles effect to scale and crop from scale.

Get raw version
php
  1. /**
  2.  * Implements hook_image_styles_alter().
  3.  *
  4.  * @param $styles
  5.  */
  6. function mymodule_image_styles_alter(&$styles) {
  7. // Init the effect data.
  8. $effects = image_image_effect_info();
  9. $scale_and_crop_effect = $effects['image_scale_and_crop'];
  10. $scale_and_crop_effect['data'] = array();
  11. $scale_and_crop_effect['weight'] = 0;
  12.  
  13. // Store styles data.
  14. $styles_data = array(
  15. 'thumbnail' => array(
  16. 'height' => 100,
  17. 'width' => 100,
  18. ),
  19. 'medium' => array(
  20. 'height' => 220,
  21. 'width' => 220,
  22. ),
  23. 'large' => array(
  24. 'height' => 480,
  25. 'width' => 480,
  26. ),
  27. );
  28.  
  29. foreach ($styles_data as $style_name => $data) {
  30. // Check that we only affect a default style.
  31. if ($styles[$style_name]['storage'] == IMAGE_STORAGE_DEFAULT) {
  32. $scale_and_crop_effect['data'] = $data;
  33. $styles[$style_name]['effects'] = array();
  34. $styles[$style_name]['effects'][] = $scale_and_crop_effect;
  35. }
  36. }
  37. }