實例一,用我們用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);
- //開源代碼Vevb.com
- // 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);
- //開源代碼Vevb.com
- $red = imagecolorallocate($png, 255, 0, 0);
- imagefilledellipse($png, 400, 300, 400, 300, $red);
- header("Content-type: image/png");
- imagepng($png);
你要做的就是創建一個真正的彩色圖像,確保阿爾法保存狀態是,然后填寫一個顏色,也經歷了阿爾法級別設置為完全透明(127)的圖像.
從上面的代碼產生的將有一個完全透明的背景,一紅色圓圈拖到Photoshop中的圖像,以了解自己.
新聞熱點
疑難解答