« imagecolorset
imagecolorstotal »

imagecolorsforindex

(PHP 4, PHP 5, PHP 7, PHP 8)

imagecolorsforindex — カラーインデックスからカラーを取得する

説明

function imagecolorsforindex(GdImage $image, int $color): array

指定したインデックスに対する色を取得します。

パラメータ

image

imagecreatetruecolor()のような画像作成関数が返す GdImage オブジェクト。

color

色インデックス。

戻り値

指定したカラーインデックス index に対して適当な値からなる red、green、blue をキーとする連想配列を返します。

変更履歴

バージョン 説明
8.0.0 image は、 GdImage クラスのインスタンスを期待するようになりました。 これより前のバージョンでは、有効な gd resource が期待されていました。
8.0.0 color が範囲外の値の場合に、 imagecolorsforindex() は ValueError をスローするようになりました。 これより前のバージョンでは、 false を返していました。

例

例1 imagecolorsforindex() の例

<?php

// 画像をオープンします
$im = imagecreatefrompng('nexen.png');

// 色を取得します
$start_x = 40;
$start_y = 50;
$color_index = imagecolorat($im, $start_x, $start_y);

// 可読形式にします
$color_tran = imagecolorsforindex($im, $color_index);

// どんな内容でしょう?
print_r($color_tran);

?>

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

Array
(
   [red] => 226
   [green] => 222
   [blue] => 252
   [alpha] => 0
)

参考

関連キーワード:
インデックス   カラー   color   imagecolorsforindex   start   GdImage   image   index   画像   green   blue   期待   imagecolorat   tran   imagecolorset   imagecolorstotal   Image   imagecreatetruecolor   適当   キー   連想   履歴   インスタンス   resource   範囲
関連する関数・ページ:
function.imagecolorat   function.imagecolorset   function.imagecolorstotal   imagickpixel.setindex   function.imagecolorresolve   function.imagecolorresolvealpha