You are here

function textimage_image_add_margin in Textimage 5

Same name and namespace in other branches
  1. 5.2 textimage.module \textimage_image_add_margin()
  2. 6.2 textimage.module \textimage_image_add_margin()
  3. 7.2 textimage.utils.inc \textimage_image_add_margin()

This function adds a margin (or border) around an existing image resource

1 call to textimage_image_add_margin()
textimage_image_from_preset in ./textimage.module
Loads the Text Image preset and generates the GD image resource.

File

./textimage.module, line 801

Code

function textimage_image_add_margin($img, $top, $right, $bottom, $left, $background_color = NULL) {
  $iw = imagesx($img);
  $ih = imagesy($img);

  // Create a new image for the background
  if (empty($background_color)) {
    $back_img = _textimage_create_transparent_image($iw + $right + $left, $ih + $top + $bottom);
  }
  else {
    $back_img = imagecreatetruecolor($iw + $right + $left, $ih + $top + $bottom);
    list($r, $g, $b) = _textimage_hex2rgb($background_color);
    $back = imagecolorallocate($back_img, $r, $g, $b);
    imagefill($back_img, 0, 0, $back);
  }

  // Apply the source image ontop the background with the new margin
  imagecopy($back_img, $img, $left, $top, 0, 0, $iw, $ih);
  return $back_img;
}