Php/docs/function.imagecolortransparent

提供:Dev Guides
< Php
移動先:案内検索

imagecolortransparent

(PHP 4, PHP 5, PHP 7)

imagecolortransparent透明色を定義する


説明

imagecolortransparent ( resource $image ) : int

imagecolortransparent ( resource $image , int $color ) : int

指定した画像 image 上の透明色を設定したり、取得したりします。


パラメータ

image
imagecreatetruecolor() のような画像作成関数が返す画像リソース。
color
imagecolorallocate() で作成された色識別子。


返り値

新しい透明色の ID (指定しなかった場合は現在設定されている ID) を返します。color を指定せず、 さらに現在の透明色も設定されていない場合は -1 を返します。


例1 imagecolortransparent() の例

<?php// 55x30 の画像を作成します$im = imagecreatetruecolor(55, 30);$red = imagecolorallocate($im, 255, 0, 0);$black = imagecolorallocate($im, 0, 0, 0);// 背景を透明にしますimagecolortransparent($im, $black);// 赤い矩形を描画しますimagefilledrectangle($im, 4, 4, 50, 25, $red);// 画像を保存しますimagepng($im, './imagecolortransparent.png');imagedestroy($im);?>

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


注意

注意:

透過性は imagecopymerge() かつ True カラーの場合のみコピーされます。imagecopy() もしくはパレットイメージの場合はコピーされません。

注意:

透明色は画像のプロパティであり、色のプロパティではありません。 ある色を透明色と定義したら、画像上で既にその色で着色されてる領域も 透明になります。