You are here

function image_focus_scale_and_crop_effect in Image Focus Crop 7

Image effect callback for image_focus_scald_and_crop.

1 string reference to 'image_focus_scale_and_crop_effect'
image_focus_image_effect_info in ./image_focus.module
Implements hook_image_effect_info().

File

./image_focus.module, line 27
Image Focus Crop module.

Code

function image_focus_scale_and_crop_effect(&$image, $data) {
  list($cx, $cy) = image_focus_get_focal_point($image);
  $scale = max($data['width'] / $image->info['width'], $data['height'] / $image->info['height']);
  if (!image_resize($image, $image->info['width'] * $scale, $image->info['height'] * $scale)) {
    return FALSE;
  }
  $x = max(0, min($image->info['width'] - $data['width'], $cx * $scale - $data['width'] / 2));
  $y = max(0, min($image->info['height'] - $data['height'], $cy * $scale - $data['height'] / 2));
  return image_crop($image, $x, $y, $data['width'], $data['height']);
}