You are here

function image_effect_imagick_advance_resize in image effect 7

File

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

Code

function image_effect_imagick_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 = new Imagick();
  if (!empty($background)) {
    $dst_image
      ->newImage($w, $h, new ImagickPixel("transparent"));
  }
  else {
    $dst_image
      ->newImage($w, $h, new ImagickPixel("white"));
  }
  $dst_image
    ->compositeImage($src_image, Imagick::COMPOSITE_DEFAULT, $dst_x, $dst_y);
  $src_image
    ->destroy();
  $image->resource = $dst_image;
  $image->info['width'] = $w;
  $image->info['height'] = $h;
  return TRUE;
}