You are here

function _media_crop_extract_rotation_and_crop in Media crop 7

Extracts the rotation and crop information from an image effect list.

It is assumed that the given effect list passed on _media_crop_effects_are_compatible().

Parameters

array $effects: List of image effects.

double $image_width: Width of original image.

double $image_height: Height of original image.

Return value

array Rotation and crop information. The result is an associative array:

  • rotation: rotation in degrees
  • crop: crop information
    • width: crop width
    • height: crop height
    • anchor: crop anchor
1 call to _media_crop_extract_rotation_and_crop()
media_crop_media_format_form_prepare_alter in ./media_crop.module
Implements hook_media_format_form_prepare_alter().

File

./media_crop.module, line 988
Media crop primary module file.

Code

function _media_crop_extract_rotation_and_crop(array $effects, $image_width, $image_height) {
  $rotation = 0;
  $crop = NULL;
  foreach ($effects as $effect) {
    switch ($effect['name']) {
      case 'image_rotate':
        $rotation = $effect['data']['degrees'];
        break;
      case 'image_crop':
        $crop = $effect['data'];
        if ($image_width && $image_height) {
          $crop = array(
            'width' => (double) _media_crop_scale($image_width, $image_height, $effect['data']['width'], TRUE),
            'height' => (double) _media_crop_scale($image_width, $image_height, $effect['data']['height'], TRUE),
            'anchor' => $effect['data']['anchor'],
          );
        }
        break;
    }
  }
  return array(
    'rotation' => $rotation,
    'crop' => $crop,
  );
}