You are here

function imageapi_gd_image_smartcrop_scale in Smart Crop 6

Scale and crop an image to the specified size using GD.

Parameters

$image_data An image object.:

$requested_x The requested image width.:

$requested_y The requested image height.:

$upscale TRUE if upscaling is allowed.:

Return value

TRUE if successful.

File

./imageapi_gd.inc, line 21
libgd implementation of smartcrop action.

Code

function imageapi_gd_image_smartcrop_scale(&$image_data, $requested_x, $requested_y, $upscale) {
  $ratio = max($requested_x / $image_data->info['width'], $requested_y / $image_data->info['height']);
  if ($ratio <= 1 || $upscale) {
    if (!imageapi_gd_image_resize($image_data, round($ratio * $image_data->info['width']), round($ratio * $image_data->info['height']))) {
      return FALSE;
    }
  }
  return imageapi_gd_image_smartcrop_crop($image_data, $requested_x, $requested_y);
}