0
我想製作透明PNG圖像,並通過imagefttext(黑色)在其上打印字符串。 我看了一些例子,我想我應該使用imagecolortransparent函數,但它會使圖像由黑色背景。 我應該怎麼做?gd
我想製作透明PNG圖像,並通過imagefttext(黑色)在其上打印字符串。 我看了一些例子,我想我應該使用imagecolortransparent函數,但它會使圖像由黑色背景。 我應該怎麼做?gd
試試這個
<?php
//Canvas size 100x50
$image = imagecreatetruecolor(100, 50);
imagealphablending($image, false);
//Create alpha channel for transparent layer
$col=imagecolorallocatealpha($image,255,255,255,127);
//Create overlapping 100x50 transparent layer
imagefilledrectangle($image,0,0,100, 50,$col);
//Continue to keep layers transparent
imagealphablending($image,true);
//Insert the text
imagefttext($image,10,0,10,20,0,'octin.ttf','test sting');
//Keep trnsparent when saving
imagesavealpha($image,true);
//Save & output
if(imagepng($image, "test.png", 1)){
header("Content-Type: image/png");
readfile('test.png');
}
imagedestroy($image);
?>
輸出100x50px [test.png]
哎呀,我忘了... r
我的壞
不錯,這是偉大的。我工作,但我不得不像這樣添加字體實時路徑指令: $ fontpath = realpath('。'); putenv('GDFONTPATH ='。$ fontpath); – rncrtr