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);