You are here

function iek_gd_filter in Image effect kit 7

Add a filter on an image by using the GD toolkit.

Parameters

object $image: An image object. The $image->resource, $image->info['width'], and $image->info['height'] values will be modified by this call.

array $data: An array that contains all the effect parameters. $data['filter_name']: the filter that will be added to an image. $data['repeat']: the times to repeat the same filter action. $data['arg1']: IMG_FILTER_BRIGHTNESS: Brightness level. IMG_FILTER_CONTRAST: Contrast level. IMG_FILTER_COLORIZE: Value of red component. IMG_FILTER_SMOOTH: Smoothness level. IMG_FILTER_PIXELATE: Block size in pixels. $data['arg2']: IMG_FILTER_COLORIZE: Value of green component. IMG_FILTER_PIXELATE: Whether to use advanced pixelation effect or not. $data['arg3']: IMG_FILTER_COLORIZE: Value of blue component. $data['arg4']: IMG_FILTER_COLORIZE: Alpha channel, A value between 0 and 127. 0 indicates completely opaque while 127 indicates completely transparent.

Return value

bool TRUE or FALSE, based on success.

File

./iek.gd.inc, line 614
GD2 toolkit for image manipulation within Drupal.

Code

function iek_gd_filter(stdClass $image, $data) {
  $filter_name = $data['filter_name'];
  $repeat = isset($data['repeat']) ? $data['repeat'] : 1;
  $arg1 = $data['arg1'];
  $arg2 = $data['arg2'];
  $arg3 = $data['arg3'];
  $arg4 = $data['arg4'];
  switch ($filter_name) {
    case IMG_FILTER_BRIGHTNESS:
    case IMG_FILTER_CONTRAST:
    case IMG_FILTER_SMOOTH:
      for ($i = 0; $i < $repeat; $i++) {
        imagefilter($image->resource, $filter_name, $arg1);
      }
      break;
    case IMG_FILTER_PIXELATE:
      for ($i = 0; $i < $repeat; $i++) {
        imagefilter($image->resource, $filter_name, $arg1, $arg2);
      }
      break;
    case IMG_FILTER_COLORIZE:
      for ($i = 0; $i < $repeat; $i++) {
        imagefilter($image->resource, $filter_name, $arg1, $arg2, $arg3, $arg4);
      }
      break;
    default:
      for ($i = 0; $i < $repeat; $i++) {
        imagefilter($image->resource, $filter_name);
      }
      break;
  }
  return TRUE;
}