You are here

function iek_gd_padding in Image effect kit 7

Add an image padding 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['padding_top']: image top padding, in pixels. $data['padding_right']: image right padding, in pixels. $data['padding_bottom']: image bottom padding, in pixels. $data['padding_left']: image left padding, in pixels. $data['bg_color']: image background color, in Hex format as #cccccc.

Return value

bool TRUE or FALSE, based on success.

File

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

Code

function iek_gd_padding(stdClass $image, $data) {
  $padding_top = $data['padding_top'];
  $padding_right = $data['padding_right'];
  $padding_bottom = $data['padding_bottom'];
  $padding_left = $data['padding_left'];
  $bg_color = $data['bg_color'];
  $width = $image->info['width'];
  $height = $image->info['height'];
  $dst = imagecreatetruecolor($width, $height);
  $bg_rgb = iek_image_hex2rgb($bg_color);
  $bg = imagecolorallocate($dst, $bg_rgb['red'], $bg_rgb['green'], $bg_rgb['blue']);
  imagefilledrectangle($dst, 0, 0, $width, $height, $bg);
  iek_gd_resize($image, array(
    'width' => $width - ($padding_left + $padding_right),
    'height' => $height - ($padding_top + $padding_bottom),
    'blank_margin' => TRUE,
    'blank_margin_bg_color' => $bg_color,
    'position' => 'middle_center',
  ));
  if (!imagecopy($dst, $image->resource, $padding_left, $padding_top, 0, 0, $width - ($padding_left + $padding_right), $height - ($padding_top + $padding_bottom))) {
    return FALSE;
  }
  imagedestroy($image->resource);

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