實(shí)例一,用我們用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);
我把這個(gè)一起 - 結(jié)合較好的例子,然后動(dòng)態(tài)生成的文本,但是,與此成立,我能得到透明背景以及工作.
實(shí)例二,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);
- //開(kāi)源代碼Vevb.com
- // Using imagepng() results in clearer text compared with imagejpeg()
- imagepng($im);
- imagedestroy($im);
實(shí)例三:創(chuàng)建透明圖片
如果你想創(chuàng)建一個(gè)PNG圖像*透明*,其中的背景是完全透明的,所有行動(dòng)發(fā)生在借鑒,除此之外,然后執(zhí)行下列操作,代碼如下:
- $png = imagecreatetruecolor(800, 600);
- imagesavealpha($png, true);
- $trans_colour = imagecolorallocatealpha($png, 0, 0, 0, 127);
- imagefill($png, 0, 0, $trans_colour);
- //開(kāi)源代碼Vevb.com
- $red = imagecolorallocate($png, 255, 0, 0);
- imagefilledellipse($png, 400, 300, 400, 300, $red);
- header("Content-type: image/png");
- imagepng($png);
你要做的就是創(chuàng)建一個(gè)真正的彩色圖像,確保阿爾法保存狀態(tài)是,然后填寫(xiě)一個(gè)顏色,也經(jīng)歷了阿爾法級(jí)別設(shè)置為完全透明(127)的圖像.
從上面的代碼產(chǎn)生的將有一個(gè)完全透明的背景,一紅色圓圈拖到Photoshop中的圖像,以了解自己.
新聞熱點(diǎn)
疑難解答