이미지 처리 및 GD 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 인스턴스를 반환합니다. 이전에는 리소스가 필요했습니다. |
Examples
예제 #1 imagesetpixel() 예제
일반 그림으로 끝나는 임의의 그림.
<?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() - 픽셀의 색상 인덱스 가져오기