php 在png格式的圖片上合成文字?該怎麼解決

來源:互聯網
上載者:User
php 在png格式的圖片上合成文字?
RT

需要在png格式的圖片上合成一些文字,但是為什麼會有黑色的背景?

原圖是

但是我產生的圖片是這樣的

瀏覽器看的效果


我需要在原圖下面的空白處合成一些字在置中位置,請高手幫幫忙!

分享到:


------解決方案--------------------
y座標400不都跑到圖片外去了嗎?
$url = 'http://img.bbs.csdn.net/upload/201310/29/1383042869_349074.png';
$im1 = imagecreatefrompng($url);

//這幾行必須有,否則原圖的陰影層過不來
$im2 = imagecreatetruecolor(imagesx($im1), imagesy($im1));
$bg = imagecolorallocate($im2, 255, 255, 255);
imagefill($im2, 0, 0, $bg);
imagecopy($im2, $im1, 0, 0, 0, 0, imagesx($im1), imagesy($im1));

#設定浮水印字型顏色
$color = imagecolorallocatealpha($im2,0,0,0,100);


#設定字型檔路徑
$fontfile = "msyhbd.ttf";
$fontfile = "c:/windows/fonts/FZJZJW.TTF";

#浮水印文字
$str = "我們都是好孩子";
$str = iconv('gbk', 'utf-8', $str);

#打浮水印
imagettftext($im2,20,20,20,100,$color,$fontfile,$str);
imagettftext($im2,20,20,30,200,$color,$fontfile,$str);
imagettftext($im2,20,20,40,300,$color,$fontfile,$str);

imagepng($im2);
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.