imagecreatetruecolor()与imagecreate()生成图像时的背景色
2014-04-29 16:47
549 查看
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);
返回一个图像标识符,代表了一幅大小为 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);
相关文章推荐
- php图像函数 imagecreatetruecolor()和imagecreate()的区别
- php图像函数 imagecreatetruecolor()和imagecreate()的区别
- php图像生成函数imagecreatetruecolor()和imagecreate()的区别
- php图像函数 imagecreatetruecolor()和imagecreate()的区别
- 利用gd库,生成一个图片 imagecreatetruecolor
- imagecreatetruecolor()和imagecreate()的区别
- imagecreate()与imagecreatetruecolor()区别
- Call to undefined function imagecreatetruecolor() imageCreate() 的gd库解决办法
- php imagecreatetruecolor 创建高清和透明图片代码小结
- php报错-Call to undefined function imagecreatetruecolor() in
- OpenCV 生成 伪彩色图像 pseudo color image 易用colorbar 调节
- php imagecreatetruecolor输出字符符或验证码
- php imagecreatetruecolor 创建高清和透明图片代码小结
- PHP错误:call to undefined function imagecreatetruecolor
- php imagecreatetruecolor()方法报未定义错误解决方法
- Fatal error: Call to undefined function imagecreatetruecolor() in
- ImageCreateTrueColor白色背景问题
- imagecreatetruecolor背景颜色的改变
- php报错 ----> Call to undefined function imagecreatetruecolor()
- 多视角图像生成--Multi-View Image Generation from a Single-View