| 7 image.api.php | hook_image_effect_info() |
| 8 image.api.php | hook_image_effect_info() |
Define information about image effects provided by a module.
This hook enables modules to define image manipulation effects for use with an image style.
Return value
An array of image effects. This array is keyed on the machine-readable effect name. Each effect is defined as an associative array containing the following items:
- "label": The human-readable name of the effect.
- "effect callback": The function to call to perform this image effect.
- "dimensions passthrough": (optional) Set this item if the effect doesn't change the dimensions of the image.
- "dimensions callback": (optional) The function to call to transform dimensions for this effect.
- "help": (optional) A brief description of the effect that will be shown when adding or configuring this image effect.
- "form callback": (optional) The name of a function that will return a $form array providing a configuration form for this image effect.
- "summary theme": (optional) The name of a theme function that will output a summary of this image effect's configuration.
See also
hook_image_effect_info_alter()
Related topics
2 functions implement hook_image_effect_info()
1 invocation of hook_image_effect_info()
File
- modules/
image/ image.api.php, line 38 - Hooks related to image styles and effects.
Code
function hook_image_effect_info() {
$effects = array();
$effects['mymodule_resize'] = array(
'label' => t('Resize'),
'help' => t('Resize an image to an exact set of dimensions, ignoring aspect ratio.'),
'effect callback' => 'mymodule_resize_effect',
'dimensions callback' => 'mymodule_resize_dimensions',
'form callback' => 'mymodule_resize_form',
'summary theme' => 'mymodule_resize_summary',
);
return $effects;
}
Login or register to post comments
Comments
things to take care around
If implementing the 'dimensions callback' - although the callback function signature expects to be given dimensions as the first argument, it's legal and occasionally expected for those dimensions to be NULL!
This is due to previous actions possible being unable to calculate sizes correctly.
If calculating your own dimensions, be sure to deal with NULL (unknown) dimensions appropriately. Avoid running maths transforms on invalid input.
See image_scale_dimensions() for an example of the check.
See image_rotate_dimensions() for an example of an image effect that can create NULL values.
See the sort of issues this can cause
The result of an image coming out of this process with NULL values is (probably) an img tag being rendered with no explicit height or width in the img tag. Due to decisions to avoid disk IO