function image_rotate_effect
image_rotate_effect(&$image, $data)
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().
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((float) $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; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!image!image.effects.inc/function/image_rotate_effect/7.x