imagecreatetruecolor()与imagecreate()生成图像时的背景色

resource imagecreatetruecolor ( int $x_size , int $y_size )

返回一个图像标识符,代表了一幅大小为 x_size 和 y_size 的黑色图像。  

resource imagecreate ( int $x_size , int $y_size )

返回一个图像标识符,代表了一幅大小为 x_size 和 y_size

两者在改变背景颜色时有些区别:

imagecreatetruecolor需要用imagefill()来填充颜色(不填充时为"黑色")

imagecreate()需要用imagecolorAllocate()添加背景色(必须填充)

php案例如下:
<?php
$img = imagecreatetruecolor(100,100);    //创建真彩图像资源
$color = imagecolorAllocate($img,200,200,200);   //分配一个灰色
imagefill($img,0,0,$color) ;                 // 从左上角开始填充灰色
header('content-type:image/jpeg');   //jpg格式
imagejpeg($img);                              //显示灰色的方块
?>
<?php
$img = imagecreate(100,100);
imagecolorallocate($img,200,200,200);
header('content-type:image/jpeg');  
imagejpeg($img); 
?>


-------------------------------------------------------------------------------------------------------------------------------------------------

数字转换成图片

// Set the content-type
header('Content-Type: image/png');    //生成的图片格式


// Create the image   
$im = imagecreatetruecolor(200, 60);      //新建一个真彩色图像


// Create some colors
$white = imagecolorallocate($im, 252, 249, 240);   //背景颜色
$grey = imagecolorallocate($im, 252, 249, 240);    //阴影颜色
$black = imagecolorallocate($im, 221, 51, 25);     //字体颜色
imagefilledrectangle($im, 0, 0, 200, 60, $white);   //画一矩形并填充


// The text to draw
$text = '1528065095';
$text = iconv('gb2312','utf-8',$text);
// Replace path by your own font path
$font = 'arial.ttf';


// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);    


// Add the text
imagettftext($im, 20, 0, 10, 40, $black, $font, $text); //10,40文字位置


imagepng($im);
imagedestroy($im);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值