array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'function.imagecolorallocate.php', 1 => 'imagecolorallocate', ), 'up' => array ( 0 => 'ref.image.php', 1 => 'GD および Image 関数', ), 'prev' => array ( 0 => 'function.imagecharup.php', 1 => 'imagecharup', ), 'next' => array ( 0 => 'function.imagecolorallocatealpha.php', 1 => 'imagecolorallocatealpha', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'ja', 'path' => 'reference/image/functions/imagecolorallocate.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
imagecolorallocate — 画像で使用する色を作成する
指定した RGB を配色とする色の ID を返します。
imagecolorallocate() は image
で表される画像上で使用する各々の色を作成する際にコールする必要があります。
注意:
imagecolorallocate() の最初のコールで パレットをもとにした画像 (imagecreate() を使用して作成した画像) で背景色がセットされます。
image
imagecreatetruecolor()のような画像作成関数が返す GdImage オブジェクト。
red
赤コンポーネントの値。
green
緑コンポーネントの値。
blue
青コンポーネントの値。
色の ID、あるいは作成に失敗した場合に false
を返します。
バージョン | 説明 |
---|---|
8.0.0 |
image は、
GdImage
クラスのインスタンスを期待するようになりました。
これより前のバージョンでは、有効な gd resource が期待されていました。
|
例1 imagecolorallocate() の例
<?php
$im = imagecreate(100, 100);
// 背景色を赤にします
$background = imagecolorallocate($im, 255, 0, 0);
// その他の色を設定します
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
// 十六進で指定します
$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
$black = imagecolorallocate($im, 0x00, 0x00, 0x00);
?>