imagesetpixel

(PHP 4, PHP 5, PHP 7, PHP 8)

imagesetpixel设置单个像素

说明

imagesetpixel(
    GdImage $image,
    int $x,
    int $y,
    int $color
): bool

imagesetpixel() 在指定坐标处绘制像素。

参数

image

由图象创建函数(例如imagecreatetruecolor())返回的 GdImage 对象。

x

x 坐标。

y

y 坐标。

color

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

返回值

成功时返回 true, 或者在失败时返回 false

更新日志

版本 说明
8.0.0 image 现在需要 GdImage 实例;之前需要有效的 gd resource

范例

示例 #1 imagesetpixel() 示例

A random drawing that ends with a regular picture.

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

?>

以上例程的输出类似于:

Output of example : imagesetpixel()

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top