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

?>

上の例の出力は、 たとえば以下のようになります。

出力例 : imagesetpixel()

参考