You are here

function image_effect_gd_advance_resize in image effect 7

File

./image_effect.module, line 87
Image Effect module file.

Code

function image_effect_gd_advance_resize(stdClass $image, $width, $height, $background) {
  $w = $width;
  $h = $height;
  $src_x = 0;
  $src_y = 0;
  $src_w = $image->info['width'];
  $src_h = $image->info['height'];
  $src_image = $image->resource;
  $dst_w = $src_w;
  $dst_h = $src_h;
  $dst_x = 0;
  $dst_y = 0;
  if ($w > $src_w) {
    $dst_x = ($w - $src_w) / 2;
  }
  if ($h > $src_h) {
    $dst_y = ($h - $src_h) / 2;
  }
  $dst_image = imagecreatetruecolor($w, $h);
  if (!empty($background)) {
    imagesavealpha($dst_image, true);
    $backgroundColor = imagecolorallocatealpha($dst_image, 0, 0, 0, 127);
  }
  else {
    $backgroundColor = imagecolorallocate($dst_image, 255, 255, 255);
  }
  imagefill($dst_image, 0, 0, $backgroundColor);
  imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
  imagedestroy($src_image);
  $image->resource = $dst_image;
  $image->info['width'] = $w;
  $image->info['height'] = $h;
  return TRUE;
}