Image effect callback; Rotate an image resource.
object $image: An image object returned by image_load().
array $data: An array of attributes to use when performing the rotate effect containing the following items:
bool TRUE on success. FALSE on failure to rotate image.
image_rotate().
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
->getPluginId(),
'%path' => $image->source,
'%mimetype' => $image->info['mime_type'],
'%dimensions' => $image->info['width'] . 'x' . $image->info['height'],
), WATCHDOG_ERROR);
return FALSE;
}
return TRUE;
}