//執行個體用我們用imagecreatetruecolor
header ('Content-type: image/png');
$im = @imagecreatetruecolor(120, 20)
or die('Cannot Initialize new GD image stream');
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
imagepng($im);
imagedestroy($im);
//我把這個一起 - 結合較好的例子,然後動態產生的文本。但是,與此成立,我能得到透明背景以及工作。
//執行個體二imagecreatetruecolor
header('Content-type: image/png');
// Create the image
$im = imagecreatetruecolor(175, 15);
imagesavealpha($im, true);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 25, $black);
$trans_colour = imagecolorallocatealpha($im, 0, 0, 0, 127);
imagefill($im, 0, 0, $trans_colour);
// The text to draw
$text = $_GET['text'];
// Replace path by your own font path
$font = 'catriel regular.ttf';
// Add some shadow to the text
imagettftext($im, 9, 0, 13, 16, $black, $font, $text);
// Add the text
imagettftext($im, 9, 0, 12, 15, $white, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
/*
執行個體三建立透明圖片
如果你想建立一個PNG映像*透明*,其中的背景是完全透明的,所有行動發生在借鑒,除此之外,然後執行下列操作:
*/
$png = imagecreatetruecolor(800, 600);
imagesavealpha($png, true);
$trans_colour = imagecolorallocatealpha($png, 0, 0, 0, 127);
imagefill($png, 0, 0, $trans_colour);
$red = imagecolorallocate($png, 255, 0, 0);
imagefilledellips教程e($png, 400, 300, 400, 300, $red);
header("Content-type: image/png");
imagepng($png);
/*
你要做的就是建立一個真正的彩色映像,確保阿爾法儲存狀態是,然後填寫一個顏色,也經曆了阿爾法層級設定為完全透明(127)的映像。
從上面的代碼產生的巴新將有一個完全透明的背景(一紅色圓圈拖到Photoshop中的映像,以瞭解自己)
The resulting PNG from the code above will have a red circle on a fully transparent background (drag the image into Photoshop to see for yourself)