php怎么添加背景色,如何添加背景色与我的这段代码在php图像创建从文本到图像?...

function create_image($user)

{

global $img_source; global $render_folder;

global $id; global $folder;

$quality = 9;

$im = imagecreatefrompng($img_source);

$clr="";

foreach ($user as $value)

{

if(!empty($_SESSION['img_name']))

{

$im = imagecreatefrompng($_SESSION['img_name']);

}

$img_width=imagesx($im);

list($r, $g, $b) = sscanf($value['color'], "#%02x%02x%02x");

$clr=imagecolorallocate($im, $r, $g, $b);

$text_a = explode(' ', $value['name']);

$text_new = ''; $width = $value['box-width']; $linex=1;

foreach($text_a as $word)

{

//Create a new text, add the word, and calculate the parameters of the text

$box = imagettfbbox($value['font-size'], 0, $folder.$value['font'], $text_new.' '.$word);

//if the line fits to the specified width, then add the word with a space, if not then add word with new line

//echo $box[2]." ";

if($box[2] > $width){

$text_new .= "\n".$word; $linex++; //echo "
";

} else {

$text_new .= " ".$word;

}

}

$text_new = trim($text_new);

$linslikh=explode("\n",$text_new); $ff=1;

foreach($linslikh as $linslikh1)

{

if($value['center']=="Y")

{

//die();

$xpos = center_text($linslikh1, $folder.$value['font'], $value['font-size'],$width);

$xpos+=$value['x'];

}

else

{

$xpos = $value['x'];

}

$acfont = $value['font-size']*$ff ; $ypos = $acfont + $value['y'];

$ff=$ff+2;

imagettftext($im, $value['font-size'], 0, $xpos, $ypos,$clr, $folder.$value['font'],$linslikh1);

// create the image

}

$output_filename = $id.'_render.png';

imagepng($im, $render_folder.$output_filename, $quality);

imagedestroy($im);

$_SESSION['img_name']=$render_folder.$output_filename;

$_SESSION['render_name']= $output_filename;

}

//die();

}

function center_text($string, $font, $font_size, $image_width){

$dimensions = imagettfbbox($font_size, 0, $font, $string);

return ceil(($image_width - $dimensions[4]) / 2);

}

?>

数据输入文件代码(从何处输入数据)

(从该文件存储的数据)其他文件代码

$new_array[]=array("name"=>$_POST['text'][$i],

"font-size"=>$_POST['font-size'][$i],

"color"=>$_POST['clr'][$i],

"background-color"=>"#".$_POST['Bclr'][$i],

上面是一些文件中我代码的一部分。我只想在我的图像中添加背景色选项。我可以添加选项和获取数据。但无法在我的php文件中添加从输入生成图像的输出。希望你明白我的意思。请帮助我如何将背景色从输入值添加到我的php文件中。对不起,英语不好。

更新:我用这种方法尝试过,但没有成功

//

// other code part

//

$Bclr="";

$clr="";

foreach ($user as $value)

//

// other code part

//

list($r, $g, $b) = sscanf($value['Bcolor'], "#%02x%02x%02x");

$Bclr=imagecolorallocate($im, $r, $g, $b);

//

// Other Code Part

//

imagettftext($im, $value['font-size'], 0, $xpos, $ypos,$clr, $Bclr,$folder.$value['font'],$linslikh1);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值