構文: array imagecolorsforindex($ image、$ index)
パラメーター:この関数は、上記の2つのパラメーターを取り、以下で説明します。 - $ image: imagecreatetruecolor()関数は、指定されたサイズの画像を作成するために使用されます。この関数は、指定されたサイズの空の画像を作成します。
- $ index:このパラメーターは、カラーインデックスを指定するために使用されます。
戻り値value:この関数は、指定されたインデックスの赤、緑、青、およびアルファキー値を含む連想配列を返します。次のプログラムは、PHPの imagecolorsforindex()関数を示しています。 :プログラム1: <? Php
//画像を変数に保存します。
$ image
= imagecreatefrompng(
` https://media.engineerforengineer.org/w p-content / uploads / engineerforengineer-9.png `
);
//パーキュラーポイントでのrgbピクセル値を計算します。
$ rgb
= imagecolorat(
$ image
、30、25);
//色の名前と値を割り当てます。
$colors
= imagecolorsforindex(
$ image
、
$ rgb
);
var_dump(
$ songs
);
?>
出力:< / b> array(4){["red"] => int(34)["green"] => int(170)["blue"] => int(66)["alpha"] = > int(0)}
プログラム2: <? Php
//画像を変数に保存します。
$ image
= imagecreatefrompng(
` https://media.engineerforengineer.org/wp-content/uploads/col1.png `
);
//インデックス値
$ index_x
= 230;
$ index_y
= 120;
//パーキュラーポイントでのrgbピクセル値を計算します。
$ rgba_color
= imagecolorat(
$ image
、
$ index_x
、
$ index_y
);
//色の名前と値を割り当てます。
$ colors
= imagecolorsforindex(
$ image
、
$ rgba_color
);
var_dump(
$ songs
);
?>
出力: array(4){["red "] => int(97)[" green "] => int(57)[" blue "] => int (104)["alpha"] => int(0)}
関連記事: - PHP | Imagecolorclosestalpha()関数
- PHP | imagecolorat()関数
リンク: http://php.net/manual/en/function.imagecolorsforindex.php