Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP GD库中为文本指定边框_Php_Gdlib - Fatal编程技术网

如何在PHP GD库中为文本指定边框

如何在PHP GD库中为文本指定边框,php,gdlib,Php,Gdlib,如何使用带有多色文本的PHP GD库为文本指定边框,其中文本颜色与边框颜色不同 如你所见: 使用以下功能为文本添加边框 您可以在这里检查示例输出 函数imagettfstroketext(&$image、$size、$angle、$x、$y、&$textcolor、&$strokecolor、$fontfile、$text、$px){ 对于($c1=($x-abs($px));$c1/http://www.johnciacia.com/2010/01/04/using-php-and-gd-to

如何使用带有多色文本的PHP GD库为文本指定边框,其中文本颜色与边框颜色不同

如你所见:


使用以下功能为文本添加边框

您可以在这里检查示例输出

函数imagettfstroketext(&$image、$size、$angle、$x、$y、&$textcolor、&$strokecolor、$fontfile、$text、$px){
对于($c1=($x-abs($px));$c1
/http://www.johnciacia.com/2010/01/04/using-php-and-gd-to-add-border-to-text/
函数ImageTTFStroketText(&$image、$size、$angle、$x、$y、&$textcolor、&$strokecolor、$fontfile、$text、$px){

对于($c1=($x-abs($px));$c1您可以使用
stil/gd text
类库。代码示例:

<?php
require __DIR__.'/../vendor/autoload.php';

use GDText\Box;
use GDText\Color;

$im = imagecreatetruecolor(500, 500);
$backgroundColor = imagecolorallocate($im, 0, 18, 64);
imagefill($im, 0, 0, $backgroundColor);

$box = new Box($im);
$box->setFontFace(__DIR__.'/Elevant bold.ttf'); // http://www.dafont.com/elevant-by-pelash.font
$box->setFontSize(150);
$box->setFontColor(new Color(255, 255, 255));
$box->setBox(20, 20, 460, 460);
$box->setTextAlign('center', 'center');

$box->setStrokeColor(new Color(255, 75, 140)); // Set stroke color
$box->setStrokeSize(3); // Stroke size in pixels

$box->draw("Elevant"); // Text to draw

header("Content-type: image/png;");
imagepng($im, null, 9, PNG_ALL_FILTERS);

改进的函数ImageTTFStroketText:圆角+更快(特别是在宽边框上)

函数imagettfstroketext(&$image、$size、$angle、$x、$y、&$textcolor、&$strokecolor、$fontfile、$text、$px){

对于($c1=($x-$px);$c1,请向我们展示您的尝试。我正在处理GD库,对质量问题有点困惑,需要您的帮助
// http://www.johnciacia.com/2010/01/04/using-php-and-gd-to-add-border-to-text/
 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);
}

$font_color = imagecolorallocate($im, 255, 255, 255);
$stroke_color = imagecolorallocate($im, 0, 0, 0);
imagettfstroketext($im, 60, 10, 300, 130, $font_color, $stroke_color, "wqy-  microhei.ttc", "简体繁體", 2);
<?php
require __DIR__.'/../vendor/autoload.php';

use GDText\Box;
use GDText\Color;

$im = imagecreatetruecolor(500, 500);
$backgroundColor = imagecolorallocate($im, 0, 18, 64);
imagefill($im, 0, 0, $backgroundColor);

$box = new Box($im);
$box->setFontFace(__DIR__.'/Elevant bold.ttf'); // http://www.dafont.com/elevant-by-pelash.font
$box->setFontSize(150);
$box->setFontColor(new Color(255, 255, 255));
$box->setBox(20, 20, 460, 460);
$box->setTextAlign('center', 'center');

$box->setStrokeColor(new Color(255, 75, 140)); // Set stroke color
$box->setStrokeSize(3); // Stroke size in pixels

$box->draw("Elevant"); // Text to draw

header("Content-type: image/png;");
imagepng($im, null, 9, PNG_ALL_FILTERS);
function imagettfstroketext(&$image, $size, $angle, $x, $y, &$textcolor, &$strokecolor, $fontfile, $text, $px) {
    for($c1 = ($x-$px); $c1 <= ($x+$px); $c1++) {
        $c2 = $y + round(sqrt($px*$px - ($x-$c1)*($x-$c1)));
        imagettftext($image, $size, $angle, $c1, $c2, $strokecolor, $fontfile, $text);
        $c3 = $y - round(sqrt($px*$px - ($x-$c1)*($x-$c1)));
        imagettftext($image, $size, $angle, $c1, $c3, $strokecolor, $fontfile, $text);
    }
   return imagettftext($image, $size, $angle, $x, $y, $textcolor, $fontfile, $text);
}