function textimage_image_add_stroke in Textimage 7.2
Same name and namespace in other branches
- 5.2 textimage.module \textimage_image_add_stroke()
- 5 textimage.module \textimage_image_add_stroke()
- 6.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
resource $img: The gd image resource of the image to modify
int $thickness: The width of the stroke to apply
hex $color: The color of the stroke to apply
1 call to textimage_image_add_stroke()
- textimage_image_from_preset in ./
textimage.module - Loads the Textimage preset and generates the GD image resource.
File
- ./
textimage.module, line 587 - Provides text to image manipulations.
Code
function textimage_image_add_stroke($img, $thickness, $color, $text_opacity) {
if ($thickness > 0) {
$width = imagesx($img);
$height = imagesy($img);
// Create a new image which we'll lay over the original.
$border_img = imagecreatetruecolor($width, $height);
$back = imagecolorallocatealpha($border_img, 0, 0, 0, 127);
imagefill($border_img, 0, 0, $back);
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 less opaque than the text
// opacity.
if ($c['alpha'] > -($text_opacity - 100) / 100 * 127) {
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;
}