You are here

function image_focus_scale_and_crop_image in Image Focus Crop 6

Image callback for the image_focus_scald_and_crop action.

File

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

Code

function image_focus_scale_and_crop_image(&$image, $data) {
  list($cx, $cy) = image_focus_get_focal_point($image);
  $scale = max($data['width'] / $image->info['width'], $data['height'] / $image->info['height']);
  if (!imageapi_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 imageapi_image_crop($image, $x, $y, $data['width'], $data['height']);
}