1 image.effects.inc image_rotate_effect(stdClass $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

core/modules/image/image.effects.inc, line 261
Functions needed to execute image effects provided by Image module.

Code

function image_rotate_effect(stdClass $image, $data) {
  // Set sane default values.
  $data += array(
    'degrees' => 0,
    'bgcolor' => NULL,
    'random' => FALSE,
  );

  // Convert any syntax to hexadecimal colors.
  if ($data['bgcolor'] != '') {
    image_hex2rgba($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;
}