You are here

function image_gd_resize in Drupal 4

Same name and namespace in other branches
  1. 5 includes/image.inc \image_gd_resize()
  2. 6 includes/image.gd.inc \image_gd_resize()
  3. 7 modules/system/image.gd.inc \image_gd_resize()

Scale an image to the specified size using GD.

File

includes/image.inc, line 217

Code

function image_gd_resize($source, $destination, $width, $height) {
  if (!file_exists($source)) {
    return false;
  }
  $info = image_get_info($source);
  if (!$info) {
    return false;
  }
  $im = image_gd_open($source, $info['extension']);
  if (!$im) {
    return false;
  }
  $res = imageCreateTrueColor($width, $height);
  if ($info['extension'] == 'png') {
    $transparency = imagecolorallocatealpha($res, 0, 0, 0, 127);
    imagealphablending($res, FALSE);
    imagefilledrectangle($res, 0, 0, $width, $height, $transparency);
    imagealphablending($res, TRUE);
    imagesavealpha($res, TRUE);
  }
  imageCopyResampled($res, $im, 0, 0, 0, 0, $width, $height, $info['width'], $info['height']);
  $result = image_gd_close($res, $destination, $info['extension']);
  imageDestroy($res);
  imageDestroy($im);
  return $result;
}