首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

imagesetpixel

(PHP 4, PHP 5, PHP 7)

imagesetpixel - 设置一个像素

描述

代码语言:javascript
复制
bool imagesetpixel ( resource $image , int $x , int $y , int $color )

imagesetpixel()在指定的坐标上绘制一个像素。

参数

代码语言:txt
复制
`image`   

一个图像资源,由图像创建函数之一返回,如imagecreatetruecolor()。

x

x坐标。

y

y坐标。

color

使用imagecolorallocate()创建的颜色标识符。

返回值

成功返回TRUE或失败时返回FALSE。

例子

示例#1 imagesetpixel()示例

以普通图片结尾的随机绘图。

代码语言:javascript
复制
<?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 →

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com