imagesetpixel

点を生成する

説明

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

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($gd25500); 

for (
$i 0$i 100000$i++) {
  
imagesetpixel($gdround($x), round($y), $red);
  
$a rand(02);
  
$x = ($x $corners[$a]['x']) / 2;
  
$y = ($y $corners[$a]['y']) / 2;
}
 
header('Content-Type: image/png');
imagepng($gd);

?>

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

出力例 : imagesetpixel()

参考

  • imagecreatetruecolor
  • imagecolorallocate
  • imagecolorat