图像函数 imagecreatetruecolor()和imagecreate()的异同点

共同点:这两个函数都是用于创建画布

区别:

1.不同的是创建画布和为画布填充颜色的流程不一样;

用imagecreatetruecolor(int x,int y)创建的是一幅大小为 x和 y的图像(默认为黑色),如想改变背景颜色则需要为画布分配颜色imagecolorallcollate(resource:image,red:int,green:int,blue:int),然后为画布填充颜色函数imagefill(resource:image,int x, int y,$color);

具体代码:

<?php

//设置文件类型为图像header(‘Content-Type:image/png‘);

//创建画布$image = imagecreatetruecolor(200,200);

//为画布分配颜色$color = imagecolorallocate($image,174,48,96);

//填充颜色imagefill($image,0,0,$color);

//生成图像imagepng($image);

//保存图像,生成图像和保存图像需要分为两步,要么只能生成,要么只能保存
imagepng($image,‘./1.png‘);
?>

用imagecreate(int x,int y)创建的也是一幅大小为 x和 y的图像(默认没有颜色,需要指定颜色),如想改变背景颜色则需要为画布分配颜色imagecolorallcollate(resource:image,red: int,green:int ,blue:int),和上面不同的是不需要填充,因为imagecolorallcollate()在imagecreate()函数创建画布的情况下自动填充.

具体代码:

<?php//设置文件类型为图像header(‘Content-Type:image/png‘);

//创建画布$image = imagecreate(200,200);

//为画布分配颜色并填充画布$color = imagecolorallocate($image,174,48,96);

//生成图像imagepng($image);
//保存图像,生成图像和保存图像需要分为两步,要么只能生成,要么只能保存imgaepng($image,‘./1.png‘);
?>

2.支持的颜色数不同,imagecreatetruecolor()支持的颜色更多一些.

原文地址:https://www.cnblogs.com/fantianlong/p/9898579.html

时间: 2024-07-31 23:04:23

图像函数 imagecreatetruecolor()和imagecreate()的异同点的相关文章

创建验证码(上)

一.创建验证码函数 验证码函数输入通用函数,将函数放入global.func.php里 //创建一个四位数的字母数字混合随机码 for($i=0;$i<4:$i++){ $_nmsg .= dechex(mt_rand(0,9)); } //将验证码保存到session里 $SESSION['code']=$_nmsg; //设定验证码图片的长度和宽度 $_width=75; $_height=25; //创建图片 $_img = imagecreatetruecolor($_width,$_h

ECSHOP错误Redefining already defined constructor for class如何解决

本地PHP环境PHP5.4,安装ecshop2.7.3后,很多地方会报如下的错 Redefining already defined constructor for class XXX 使用和类名相同点函数名作为构造函数是php4时代的写法,php5时代的构造函数是 __construct(),ecshop为了兼容老版本的php,所以采用了上面的写法. 但是从php5.4开始,对于这样的两种写法同时出现的情况,要求必须__construct()在前,同名函数在后,所以只需要对调两个函数的位置即可

PHP生成制作验证码

看完就会,不会你打我,话不多说.开搞(人狠话不多) 1.0 首先先看代码 1 <?php 2 header("Content-Type:text/html;Charset=UTF-8");// 设置页面的编码风格 3 header("Content-Type:image/jpeg");// 通知浏览器输出的是jpeg格式的图像 4 5 $img = imagecreatetruecolor(150,50);//创建画布并设置大小 x轴150 y轴50 6 7

ECShop 环境搭建报错处理集锦

1.ECSHOP错误Redefining already defined constructor for class如何解决 打开includes/cls_capcha.php,将函数 function captcha($folder = '', $width = 145, $height = 20) { if (!empty($folder)) { $this->folder = $folder; } $this->width = $width; $this->height = $he

php基础教程:图像函数举例(3)

php基础教程:图像函数举例(3) 例二: 阴阳图 <?php $width=400; $height=400; $image=imagecreatetruecolor($width,$height); //提取颜色 $color_black=imagecolorallocate($image,0,2,0);// $color_white=imagecolorallocate($image,255,255,255);//白色 $color_blue=imagecolorallocate($ima

php提示Fatal error: Call to undefined function imagecreate()

在php中imagecreate函数是一个图形处理函数,主要用于新建一个基于调色板的图像了,然后在这个基础上我们可以创建一些图形数字字符之类的,但这个函数需要GD库支持,如果没有开启GD库使用时会 undefined 在php中imagecreate函数是一个图形处理函数,主要用于新建一个基于调色板的图像了,然后在这个基础上我们可以创建一些图形数字字符之类的,但这个函数需要GD库支持,如果没有开启GD库使用时会提示Call to undefined function imagecreate()错

PHP图像函数

http://blog.sina.com.cn/s/blog_68b56adb0100vq1a.html 相册程序.图片缩略图的生成是必不可少的一个功能,用PHP的GD函数为图片生成缩略图是很简单的,核心就一个 imagecopyresampled函数.主要麻烦的是要考虑图片的各种长.宽.缩放比等等东西. 如果对缩略图的质量要求不高可以使用imagecopyresized()函数,imagecopyresize()所生成的图像比较粗糙,但是速度较快:imagecopyresampled()函数是

php imagecreatetruecolor输出字符符或验证码

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

架构(三层架构)、框架(MVC)、设计模式三者异同点

对于没有排序功能的集合来说,都可以使用java.util.Collections.sort()方法进行排序,它除了集合对象以外,还需要提供一个比较器.如果列表中的元素全部都是相同的类型,并且这个类实现了Comparable接口,就可以简单的调用Collections.sort()方法,如果这个类没有实现comparable接口,那么可以创建一个比较器传递一个Comparator实例作为Sort()的第二个参数进行排序,另外,如果不想使用默认的分类顺序进行排序,同样也可以传递一个Comparato