Created
November 7, 2010 19:57
-
-
Save johnciacia/666370 to your computer and use it in GitHub Desktop.
Add a border to text using GD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Writes the given text with a border into the image using TrueType fonts. | |
* @author John Ciacia | |
* @param image An image resource | |
* @param size The font size | |
* @param angle The angle in degrees to rotate the text | |
* @param x Upper left corner of the text | |
* @param y Lower left corner of the text | |
* @param textcolor This is the color of the main text | |
* @param strokecolor This is the color of the text border | |
* @param fontfile The path to the TrueType font you wish to use | |
* @param text The text string in UTF-8 encoding | |
* @param px Number of pixels the text border will be | |
* @see http://us.php.net/manual/en/function.imagettftext.php | |
*/ | |
function imagettfstroketext(&$image, $size, $angle, $x, $y, &$textcolor, &$strokecolor, $fontfile, $text, $px) { | |
for($c1 = ($x-abs($px)); $c1 <= ($x+abs($px)); $c1++) | |
for($c2 = ($y-abs($px)); $c2 <= ($y+abs($px)); $c2++) | |
$bg = imagettftext($image, $size, $angle, $c1, $c2, $strokecolor, $fontfile, $text); | |
return imagettftext($image, $size, $angle, $x, $y, $textcolor, $fontfile, $text); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment