function textimage_image_add_stroke in Textimage 5
Same name and namespace in other branches
- 5.2 textimage.module \textimage_image_add_stroke()
- 6.2 textimage.module \textimage_image_add_stroke()
- 7.2 textimage.module \textimage_image_add_stroke()
Stroke function adds a solid color stroke around an image with a transparent background.
@todo Add $position parameter to allow the stroke to be applied 'inside', 'middle', or 'outside'. outside is the only current behavior.
Parameters
$img: The gd image resource of the image to modify
$thickness: The width of the stroke to apply
$color: The color of the stroke to apply
1 call to textimage_image_add_stroke()
- textimage_image_from_preset in ./
textimage.module - Loads the Text Image preset and generates the GD image resource.
File
- ./
textimage.module, line 835
Code
function textimage_image_add_stroke($img, $thickness, $color) {
if ($thickness > 0) {
$width = imagesx($img);
$height = imagesy($img);
// Create a new image which we'll lay over the original
$border_img = _textimage_create_transparent_image($width, $height);
for ($x = 0; $x < $width; $x++) {
for ($y = 0; $y < $height; $y++) {
$c = imagecolorsforindex($img, imagecolorat($img, $x, $y));
// Outside only modify pixels which are not 100% opaque
if ($c['alpha'] > 0) {
textimage_image_stroke_change_pixels($img, $border_img, $thickness, $color, $x, $y, $width, $height);
}
}
}
// Merge the images
imagealphablending($img, true);
imagecopy($img, $border_img, 0, 0, 0, 0, $width, $height);
}
return $img;
}