imagecolorexact
(PHP 4, PHP 5, PHP 7)
imagecolorexact — 指定した色のインデックスを取得する
説明
imagecolorexact
( resource $image
, int $red
, int $green
, int $blue
) : int
画像パレット中の特定の色のインデックスを返します。
画像をファイルから作成した場合は、画像内で使われている色だけを解決します。パレットにだけ存在する色は解決されません。
パラメータ
image
- imagecreatetruecolor() のような画像作成関数が返す画像リソース。
red
- 赤コンポーネントの値。
green
- 緑コンポーネントの値。
blue
- 青コンポーネントの値。
返り値
指定した色の、パレット内でのインデックスを返します。 画像パレット中に色が存在しない場合は -1 を返します。
例
例1 GD ロゴからの色の取得
<?php// 画像を用意します$im = imagecreatefrompng('./gdlogo.png');$colors = Array();$colors[] = imagecolorexact($im, 255, 0, 0);$colors[] = imagecolorexact($im, 0, 0, 0);$colors[] = imagecolorexact($im, 255, 255, 255);$colors[] = imagecolorexact($im, 100, 255, 52);print_r($colors);// メモリから解放しますimagedestroy($im);?>
上の例の出力は、 たとえば以下のようになります。
Array ( [0] => 16711680 [1] => 0 [2] => 16777215 [3] => 6618932 )