You are here

function image_imagick_convert in Imagick 7

Image effect form callback for the convert image format effect.

Parameters

array $data: The current configuration for this image effect.

Return value

array The form definition for this effect.

File

effects/imagick.convert.inc, line 12

Code

function image_imagick_convert(stdClass $image, $format, $quality) {
  $formats = imagick_file_formats();

  // Set a white background color when converting to JPG because this file
  // format does not support transparency
  if ($format == 'image/jpeg') {
    $background = new Imagick();
    $background
      ->newImage($image->info['width'], $image->info['height'], 'white');
    $image->resource
      ->compositeImage($background, Imagick::COMPOSITE_DSTOVER, 0, 0);
  }
  $image->resource
    ->setImageProperty('quality', (int) $quality);
  $image->resource
    ->setImageFormat($formats[$format]);
  return $image;
}