I'm bit confused about this.. is there any way to add boarder to the image text?
Its' not possible out of the box. But you can access the GD or Imagick object with getCore, so maybe glow effects can be achieved with certain library functions of GD/Imagick.
I know this was closed some time ago, but I found the issue on Google while looking into a way to do this. I think that this actually may be possible without necessitating the use of the getCore function. I've done the following in order to try and create a glow effect and I've _nearly_ had success:
$text = "Foobar";
$textX = 50;
$textY = 50;
// Open image
$image = Image::make('foo.jpg');
// Create empty layer to put text on
$textLayer = Image::canvas( $image->width(), $image->height() );
// Draw four instances of the glow at different corners
$textLayer->text($text, $textX - 2, $textY - 2, function($font) {
$font->file('...');
$font->size(40);
$font->color('#ffffff'); // Glow color
});
$textLayer->text($text, $textX - 2, $textY + 2, function($font) {
$font->file('...');
$font->size(40);
$font->color('#ffffff'); // Glow color
});
$textLayer->text($text, $textX + 2, $textY - 2, function($font) {
$font->file('...');
$font->size(40);
$font->color('#ffffff'); // Glow color
});
$textLayer->text($text, $textX + 2, $textY + 2, function($font) {
$font->file('...');
$font->size(40);
$font->color('#ffffff'); // Glow color
});
// Apply a blur so the glow looks... glowy
$textLayer->blur(4);
// Place standard text on top of the glow effect
$textLayer->text($text, $textX, $textY, function($font) {
$font->file('...');
$font->size(40);
$font->color('#000000'); // Text color
});
// Combine the two layers
$image->insert($textLayer);
When I output just the text layer:
return Response::make($textLayer->encode('png'))->header('Content-Type', 'image/png');
It has the glow and looks perfect. However after compositing the two layers the glow effect is lost and you get five instances of the text overlapping -- four white and one black.
If I could get assistance in understanding the nature of this problem (Possibly a bug in Intervention? Possibly a bug in Imagick? Possibly just me not understanding what I'm doing?) then I would think a blurredText method could be added as a shortcut to the above.
Similarly for outlined text you simply don't apply the blur method -- although if you want a border thicker than a single pixel then you might need more than 4 instances of the text to be sure there are no gaps around your serifs.
A quick update:
After some further Googling I found the following: http://www.imagemagick.org/Usage/bugs/blur_trans/
It turns out the reason returning $textLayer worked but $image did not was not a compositing glitch, but because in order to see the glow effect I was adding a background to my $textLayer - it's a glitch that occurs when you blur with no background.
This got me experimenting and I developed the following for successfully adding a blur:
$text = "Foobar";
$textX = 50;
$textY = 50;
// Open image
$image = Image::make('foo.jpg');
// Create empty layer to put text on
// Change 1: The canvas must have a **black** background. This is due to the Imagick transparent blur bug. Give it an alpha of 0.
$textLayer = Image::canvas( $image->width(), $image->height(), array(0, 0, 0, 0) );
// Draw four instances of the glow at different corners
// Change 2: Just four instances was insufficient for a good blur. I added 25
for( $x = -2; $x <= 2; $x++ ) {
for( $y = -2; $y <= 2; $y++ ) {
$textLayer->text($text, $textX + $x, $textY + $y, function($font) {
$font->file('...');
$font->size(40);
$font->color('#ffffff'); // Glow color
});
}
}
// Apply a blur so the glow looks... glowy
$textLayer->blur(10);
// Place standard text on top of the glow effect
$textLayer->text($text, $textX, $textY, function($font) {
$font->file('...');
$font->size(40);
$font->color('#000000'); // Text color
});
// Combine the two layers
$image->insert($textLayer);
This produced the desired effect: glowing text. Note that the boundaries on $x and $y can be adjusted to increase or decrease the glow radius, and the value on blur() should be adjusted to compensate.
Most helpful comment
A quick update:
After some further Googling I found the following: http://www.imagemagick.org/Usage/bugs/blur_trans/
It turns out the reason returning
$textLayerworked but$imagedid not was not a compositing glitch, but because in order to see the glow effect I was adding a background to my$textLayer- it's a glitch that occurs when you blur with no background.This got me experimenting and I developed the following for successfully adding a blur:
This produced the desired effect: glowing text. Note that the boundaries on
$xand$ycan be adjusted to increase or decrease the glow radius, and the value onblur()should be adjusted to compensate.