好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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 );  //开源代码phpfensi.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 );    //开源代码phpfensi.com     $red  = imagecolorallocate( $png , 255, 0, 0);   imagefilledellipse( $png , 400, 300, 400, 300,  $red );      header( "Content-type: image/png" );   imagepng( $png ); 

你要做的就是创建一个真正的彩色图像,确保阿尔法保存状态是,然后填写一个颜色,也经历了阿尔法级别设置为完全透明(127)的图像.

从上面的代码产生的将有一个完全透明的背景,一红色圆圈拖到Photoshop中的图像,以了解自己.

 

查看更多关于php利用imagecreatetruecolor动态生成高清图片代码的详细内容...

  阅读:57次