English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
imagecolorallocatealpha — 画像に色と透明度を割り当てます。
int imagecolorallocatealpha ( resource $image , int $red , int $green , int $blue , int $alpha )
imagecolorallocatealpha() の動作は imagecolorallocate() と同じですが、追加の透明度パラメータ alpha を持っており、その値は 0 から 127。0 は完全不透明を意味します,127 完全に透明です。
割り当てが失敗すると FALSE を返します。
注意:この関数は GD を必要とします 2.0.1 またはそれ以降のバージョン(推奨) 2.0.28 およびそれ以降のバージョン)。
<?php $size = 300; $image=imagecreatetruecolor($size, $size); // 白色の背景と黒い枠で四角を描きます $back = imagecolorallocate($image, 255, 255, 255); $border = imagecolorallocate($image, 0, 0, 0); imagefilledrectangle($image, 0, 0, $size - 1, $size - 1, $back); imagerectangle($image, 0, 0, $size - 1, $size - 1, $border); $yellow_x = ; 100; $yellow_y = ; 75; $red_x = ; 120; $red_y = ; 165; $blue_x = ; 187; $blue_y = ; 125; $radius = ; 150; // alpha値で色を割り当てます $yellow = imagecolorallocatealpha($image, 255, 255, 0, 75); $red = imagecolorallocatealpha($image, 255, 0, 0, 75); $blue = imagecolorallocatealpha($image, 0, 0, 255, 75); // 3つの重なった円を描きます imagefilledellipse($image, $yellow_x, $yellow_y, $radius, $radius, $yellow); imagefilledellipse($image, $red_x, $red_y, $radius, $radius, $red); imagefilledellipse($image, $blue_x, $blue_y, $radius, $radius, $blue); // 正しい headerを忘れないでください! header('Content-type: image/png'); // 最終出力結果 imagepng($image); imagedestroy($image); ?>
以下の例の出力結果の画像はこちらです:
imagecolorallocate() 画像に色を割り当てます。
imagecolordeallocate() 画像の色の割り当てを解除します。