画像を透過する

imagealphablending

透過指定を行う


サンプル

<?php
	// 200×200の画像リソースを作成
	$im =  imagecreatetruecolor(200, 200);
 
	// 色を作成
	$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);		// 白色
 
	// 背景色を描画する
	imagefilledrectangle($im, 0, 0, 200, 200, $white);
 
 	// 楕円を描画
 	$red   = imagecolorresolvealpha($im, 0xFF, 0x32, 0x00, 0x3F);	// 赤
 	imagefilledellipse($im, 75, 75, 80, 50, $red);
 
 	// アルファブレンディングを有効
 	imagealphablending($im, true);	// ここ以下で使用した色に透過色を指定していた場合は透過する
 
	// 短形を描画する
	$gray  = imagecolorresolvealpha($im, 0x46, 0x46, 0x46, 0x3F);	// 灰色
	imagefilledrectangle($im, 60, 60, 120, 120, $gray);
 
	// 画像出力
	header("Content-type: image/png");
	ImagePNG($im);
?>
 

イメージ



最終更新:2012年08月18日 22:49