English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP 기초 강의

PHP 고급 강의

PHP & MySQL

PHP 참조 가이드

PHP imagecolorsforindex() 특정 인덱스의 색상 사용법 및 예제

PHP 이미지 처리

imagecolorsforindex — 특정 인덱스의 색상을 얻습니다.

문법

array imagecolorsforindex ( resource $image , int $index )

이 함수는 red, green, blue, alpha의 키를 가진 연관 배열을 반환하며, 지정된 색상 인덱스의相应的 값을 포함합니다.

예제

<?php
// 이미지를 엽니다
$im = imagecreatefrompng('w3codebox-logo.png');
// 일점의 색상을 얻습니다
$start_x = 40;
$start_y = 20;
$color_index = imagecolorat($im, $start_x, $start_y);
// 읽을 수 있게 합니다
$color_tran = imagecolorsforindex($im, $color_index);
// 이 색상의 값을 표시합니다
print_r($color_tran);
?>

위 예제의 출력은 다음과 같습니다:

Array
(
    [red] => 195
    [green] => 223
    [blue] => 165
    [alpha] => 64
)

관련 기사

PHP 이미지 처리