You are here

function textimage_image_add_margin in Textimage 5.2

Same name and namespace in other branches
  1. 5 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 Textimage preset and generates the GD image resource.

File

./textimage.module, line 432

Code

function textimage_image_add_margin($img, $margin) {
  $width = imagesx($img);
  $height = imagesy($img);

  // Create a new image for the background
  $back_img = imagecreatetruecolor($width + $margin['right'] + $margin['left'], $height + $margin['top'] + $margin['bottom']);
  $back = imagecolorallocatealpha($back_img, 0, 0, 0, 127);
  imagefill($back_img, 0, 0, $back);

  // Apply the source image ontop the background with the new margin
  imagecopy($back_img, $img, $margin['left'], $margin['top'], 0, 0, $width, $height);
  imagealphablending($back_img, TRUE);
  imagesavealpha($back_img, TRUE);
  return $back_img;
}