php创建透明图片,php imagecreatetruecolor 创建高清和透明图片代码小结

//实例用我们用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)

这就是微学网-程序员之家为你提供的"php imagecreatetruecolor 创建高清和透明图片代码小结"希望对你有所帮助.本文来自网络,转载请注明出处:http://www.weixuecn.cn/article/869.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值