Page 1 of 1

Stroke around text

Posted: Mon Jun 13, 2005 8:14 am
by Lucvh
This code, gets a file, and writes some text over the top.

Code: Select all

<?php
//post headers. Tells client file is type gif
header("Content-type: image/jpeg");
//load in the text using GET. 'text' is a variable in the GET method
$string = $_GET['text'];
$string2 = $_GET['text2'];
//Load the image
$im    = imagecreatefromjpeg("riots.jpg");
//make a variable to set the text color
$blue = imagecolorallocate($im, 0x78, 0x74, 0x8f);
$red = imagecolorallocate($im, 0xaf, 0x33, 0x3c);
//load the font
$font = 'gf.ttf';
$font2 = 'ang.ttf';
//draw the text onto the image
imagettftext($im, 20, 0, 110, 680, $blue, $font, $string);
imagettftext($im, 210, 0, 50, 600, $red, $font2, $string2);
//print the image
imagegif($im);
//delete the evidence
imagedestroy($im);
?>
Is there any way that i can code it so that it draws a stroke around the $string2 text?

Posted: Mon Jun 13, 2005 8:44 am
by anjanesh
I dont know how you can do this using Font properties like underline, bold, stroke etc.
You know (x,y) => (50, 600)

Use imagettfbbox() to get the width and height of the font.
Use imageline to draw a line -
(50, 600 + height/2) to (50 + width, 600 + height/2)

Posted: Mon Jun 13, 2005 9:23 am
by Lucvh
I dont't mean a stroke through the text, i mean around the outline of the text.

Posted: Mon Jun 13, 2005 12:23 pm
by anjanesh
Same method :
imagerectangle() - (50, 600) to (width, height)

Posted: Mon Jun 13, 2005 4:46 pm
by pickle
You mean like making a coloured line follow the contours of the individual letters? I've never seen that done - it sounds quite complicated.

The only way I could think of (although I'm by no means a GD guru) would be to do it letter by letter. Create a letter +2 font size (or whatever), find the pixel of the exact center of that letter, and place the inner coloured leter at those co-ordinates.

Personally if that's the only way to do it, I'd forget it and move on.

Posted: Tue Jun 14, 2005 4:58 am
by Syranide
the general straight on method for doing this is very simple, however not so fast and not accurate, but at least gives you an outline... and it is really simple, you want 1px border? then you draw the text 8 times, each time you position it at most 1px from the origin. such as N NE E SE S SW W NE, and then on that you draw in the text again using the inner color. and voila you have an outline, (don't know, but I believe if you keep it to angles of length 1 instead you might get better result.)

2px needs however a lot of more draws and so on, but you get the point.