PHP to compose text on a PNG-formatted image?
Rt
You need to synthesize some text in PNG format, but why do you have a black background?
The original is
But the picture I generated was like this.
browser-Viewing effects
I need to be in the white space below the original image to synthesize some words in the center position, please help the master!
Share to:
------Solution--------------------
Y-coordinate 400 didn't all go out of the picture?
$url = ' http://img.bbs.csdn.net/upload/201310/29/1383042869_349074.png ';
$im 1 = imagecreatefrompng ($url);
These lines must have, otherwise the shadow layer of the original is not over
$im 2 = Imagecreatetruecolor (Imagesx ($im 1), Imagesy ($im 1));
$BG = Imagecolorallocate ($im 2, 255, 255, 255);
Imagefill ($im 2, 0, 0, $BG);
Imagecopy ($im 2, $im 1, 0, 0, 0, 0, imagesx ($im 1), Imagesy ($im 1));
#设置水印字体颜色
$color = Imagecolorallocatealpha ($im 2,0,0,0,100);
#设置字体文件路径
$fontfile = "Msyhbd.ttf";
$fontfile = "C:/WINDOWS/FONTS/FZJZJW. TTF ";
#水印文字
$str = "We are all good children";
$str = Iconv (' GBK ', ' utf-8 ', $str);
#打水印
Imagettftext ($im 2,20,20,20,100, $color, $fontfile, $STR);
Imagettftext ($im 2,20,20,30,200, $color, $fontfile, $STR);
Imagettftext ($im 2,20,20,40,300, $color, $fontfile, $STR);
Imagepng ($im 2);