라이브러리
[PHP] imagecolorat - 픽셀 색상 인덱스 가져오기
이미지 색상 가져오기 (imagecolorat)
PHP의 GD 라이브러리는 이미지 처리를 위한 강력한 도구입니다. `imagecolorat` 함수는 이미지에서 특정 픽셀의 색상을 가져올 수 있는 함수입니다.
사용법
`imagecolorat` 함수의 사용법은 다음과 같습니다.
#hostingforum.kr
php
imagecolorat(image, x, y)
* `image`: 이미지 리소스
* `x`: 픽셀의 x 좌표
* `y`: 픽셀의 y 좌표
예제
다음 예제는 `imagecolorat` 함수를 사용하여 이미지에서 특정 픽셀의 색상을 가져오는 방법을 보여줍니다.
#hostingforum.kr
php
// 이미지 생성
$image = imagecreate(100, 100);
$white = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $white);
// 특정 픽셀의 색상 가져오기
$pixel_color = imagecolorat($image, 50, 50);
echo "픽셀 색상: " . dechex($pixel_color) . "
";
// 이미지 출력
header('Content-Type: image/png');
imagepng($image);
imagedestroy($image);
이 예제에서는 100x100 크기의 흰색 이미지를 생성하고, 50, 50 픽셀의 색상을 가져옵니다. 가져온 색상은 16진수 형태로 출력됩니다.
참고
`imagecolorat` 함수는 이미지의 픽셀 색상을 가져올 때 사용할 수 있습니다. 이 함수는 이미지의 x, y 좌표를 입력받아, 해당 픽셀의 색상을 16진수 형태로 반환합니다. 이 함수는 이미지 처리를 위한 다양한 작업에 사용할 수 있습니다.
예제 2: 이미지에서 특정 색상을 찾기
다음 예제는 `imagecolorat` 함수를 사용하여 이미지에서 특정 색상을 찾는 방법을 보여줍니다.
#hostingforum.kr
php
// 이미지 생성
$image = imagecreate(100, 100);
$red = imagecolorallocate($image, 255, 0, 0);
imagefilledrectangle($image, 0, 0, 50, 50, $red);
// 특정 색상 찾기
$target_color = imagecolorat($image, 25, 25);
echo "찾을 색상: " . dechex($target_color) . "
";
// 이미지 출력
header('Content-Type: image/png');
imagepng($image);
imagedestroy($image);
이 예제에서는 100x100 크기의 빨간색 이미지를 생성하고, 25, 25 픽셀의 색상을 가져옵니다. 가져온 색상은 16진수 형태로 출력됩니다.
이 예제는 이미지에서 특정 색상을 찾는 방법을 보여줍니다. 이 함수는 이미지 처리를 위한 다양한 작업에 사용할 수 있습니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.