function image_rotate_effect in Drupal 7
Image effect callback; Rotate an image resource.
Parameters
$image: An image object returned by image_load().
$data: An array of attributes to use when performing the rotate effect containing the following items:
- "degrees": The number of (clockwise) degrees to rotate the image.
- "random": A boolean indicating that a random rotation angle should be used for this image. The angle specified in "degrees" is used as a positive and negative maximum.
- "bgcolor": The background color to use for exposed areas of the image. Use web-style hex colors (#FFFFFF for white, #000000 for black). Leave blank for transparency on image types that support it.
Return value
TRUE on success. FALSE on failure to rotate image.
See also
image_rotate().
1 call to image_rotate_effect()
- ImageEffectsUnitTest::testRotateEffect in modules/
image/ image.test - Test the image_rotate_effect() function.
1 string reference to 'image_rotate_effect'
- image_image_effect_info in modules/
image/ image.effects.inc - Implements hook_image_effect_info().
File
- modules/
image/ image.effects.inc, line 253 - Functions needed to execute image effects provided by Image module.
Code
function image_rotate_effect(&$image, $data) {
// Set sane default values.
$data += array(
'degrees' => 0,
'bgcolor' => NULL,
'random' => FALSE,
);
// Convert short #FFF syntax to full #FFFFFF syntax.
if (strlen($data['bgcolor']) == 4) {
$c = $data['bgcolor'];
$data['bgcolor'] = $c[0] . $c[1] . $c[1] . $c[2] . $c[2] . $c[3] . $c[3];
}
// Convert #FFFFFF syntax to hexadecimal colors.
if ($data['bgcolor'] != '') {
$data['bgcolor'] = hexdec(str_replace('#', '0x', $data['bgcolor']));
}
else {
$data['bgcolor'] = NULL;
}
if (!empty($data['random'])) {
$degrees = abs((double) $data['degrees']);
$data['degrees'] = rand(-1 * $degrees, $degrees);
}
if (!image_rotate($image, $data['degrees'], $data['bgcolor'])) {
watchdog('image', 'Image rotate failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array(
'%toolkit' => $image->toolkit,
'%path' => $image->source,
'%mimetype' => $image->info['mime_type'],
'%dimensions' => $image->info['width'] . 'x' . $image->info['height'],
), WATCHDOG_ERROR);
return FALSE;
}
return TRUE;
}