PHP to compose text on a PNG-formatted image? How to solve it

Source: Internet
Author: User
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);
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.