imagesetpixel
(PHP 4, PHP 5, PHP 7)
imagesetpixel - 设置一个像素
描述
bool imagesetpixel ( resource $image , int $x , int $y , int $color )
imagesetpixel()在指定的坐标上绘制一个像素。
参数
`image`
一个图像资源,由图像创建函数之一返回,如imagecreatetruecolor()。
x
x坐标。
y
y坐标。
color
使用imagecolorallocate()创建的颜色标识符。
返回值
成功返回TRUE或失败时返回FALSE。
例子
示例#1 imagesetpixel()示例
以普通图片结尾的随机绘图。
<?php
$x?=?200;
$y?=?200;
$gd?=?imagecreatetruecolor($x,?$y);
?
$corners[0]?=?array('x'?=>?100,?'y'?=>??10);
$corners[1]?=?array('x'?=>???0,?'y'?=>?190);
$corners[2]?=?array('x'?=>?200,?'y'?=>?190);
$red?=?imagecolorallocate($gd,?255,?0,?0);?
for?($i?=?0;?$i?<?100000;?$i++)?{
??imagesetpixel($gd,?round($x),round($y),?$red);
??$a?=?rand(0,?2);
??$x?=?($x?+?$corners[$a]['x'])?/?2;
??$y?=?($y?+?$corners[$a]['y'])?/?2;
}
?
header('Content-Type:?image/png');
imagepng($gd);
?>
上面的例子会输出类似于:
扩展内容
- imagecreatetruecolor() - 创建一个新的真彩色图像
- imagecolorallocate() - 为图像分配颜色
- imagecolorat() - 获取像素颜色的索引
← imagesetinterpolation
imagesetstyle →
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com