You are here

function iek_gd_border in Image effect kit 7

Add an image border 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['border_color']: image border color, in Hex format as #cccccc. $data['border_thick_top']: image top border thick, in pixels. $data['border_thick_right']: image right border thick, in pixels. $data['border_thick_bottom']: image bottom border thick, in pixels. $data['border_thick_left']: image left border thick, in pixels.

Return value

bool TRUE or FALSE, based on success.

File

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

Code

function iek_gd_border(stdClass $image, $data) {
  $border_color = $data['border_color'];
  $border_thick_top = $data['border_thick_top'];
  $border_thick_right = $data['border_thick_right'];
  $border_thick_bottom = $data['border_thick_bottom'];
  $border_thick_left = $data['border_thick_left'];
  $width = $image->info['width'];
  $height = $image->info['height'];
  $border_rgb = iek_image_hex2rgb($border_color);
  $bg_rgb = iek_image_hex2rgb('#ffffff');
  $dst = imagecreatetruecolor($width, $height);

  // Creates background.
  $bg = imagecolorallocate($dst, $bg_rgb['red'], $bg_rgb['green'], $bg_rgb['blue']);

  // Defines border color.
  $border_colors = imagecolorallocate($dst, $border_rgb['red'], $border_rgb['green'], $border_rgb['blue']);
  imagefilledrectangle($dst, 0, 0, $width, $height, $border_colors);
  imagefilledrectangle($dst, $border_thick_left, $border_thick_top, $width - $border_thick_right - 1, $height - $border_thick_bottom - 1, $bg);
  iek_gd_resize($image, array(
    'width' => $width - ($border_thick_left + $border_thick_right),
    'height' => $height - ($border_thick_top + $border_thick_bottom),
    'blank_margin' => FALSE,
    'blank_margin_bg_color' => $border_color,
    'position' => 'middle_center',
  ));
  if (!imagecopy($dst, $image->resource, $border_thick_left, $border_thick_top, 0, 0, $width - ($border_thick_left + $border_thick_right), $height - ($border_thick_top + $border_thick_bottom))) {
    return FALSE;
  }

  // Update image object.
  $image->resource = $dst;
  $image->info['width'] = $width;
  $image->info['height'] = $height;
  return TRUE;
}