이미지 세트픽셀() 나열된 좌표에서 단일 픽셀을 설정하는 데 사용되는 PHP의 내장 함수입니다.
구문
bool imagesetpixel(resource $image, int $x, int $y, int $color)
매개변수
이미지 세트픽셀() 4개의 매개변수 허용:$image , $x , $y 및 $color .
-
$이미지 − 작업할 이미지 리소스를 지정합니다.
-
$x - 픽셀의 x 좌표를 지정합니다.
-
$y - 픽셀의 y 좌표를 지정합니다.
-
$color − 픽셀의 색상을 지정합니다.
반환 값 -
이미지 세트픽셀() 성공하면 True, 실패하면 False를 반환합니다.
예시 1
<?php
// Load the png image using imagecreatefromjpeg() function
$img = imagecreatefromjpeg('C:\xampp\htdocs\test\29.jpg');
// Draw the line using imagesetpixel() function
$blue = imagecolorallocate($img, 255, 255, 0);
for ($i = 0; $i < 1000; $i++) {
imagesetpixel($img, $i, 100, $blue);
}
// Show the output image to the browser
header('Content-type: image/png');
imagepng($img);
?> 출력

예시 2
<?php
$x = 700;
$y = 300;
$gd = imagecreatetruecolor($x, $y);
$corners[0] = array('x' => 100, 'y' => 10);
$corners[1] = array('x' => 0, 'y' => 170);
$corners[2] = array('x' => 190, 'y' => 170);
$blue = imagecolorallocate($gd, 255, 0, 0);
for ($i = 0; $i < 100000; $i++) {
imagesetpixel($gd, round($x),round($y), $blue);
$a = rand(0, 2);
$x = ($x + $corners[$a]['x']) / 2;
$y = ($y + $corners[$a]['y']) / 2;
}
header('Content-Type: image/png');
imagepng($gd);
?> 출력
