# php-gd で透過PNGを書く

- リンク: https://torounit.com/blog/php-gd-%e3%81%a7%e9%80%8f%e9%81%8epng%e3%82%92%e6%9b%b8%e3%81%8f/
- 公開日: 2010-08-27T12:11:46+09:00
- 作成者: Toro\_Unit

仕事で必要になったので、GDの勉強がてら、円を透過PNGで書き出すサンプルです。

[php]
 <?php $img = imagecreatetruecolor(111, 111);//からのキャンバスの作成 $backgroundColor
= imagecolorallocate($img, 255, 255, 255);//背景色セット imagefill($img, 0, 0, $
backgroundColor); // 背景を塗る。 imagecolortransparent($img,$backgroundColor);//
透明化

// 楕円の色を選択します
 $color = imagecolorallocate($img, 220, 90, 90); $color2
= imagecolorallocate($img, 255, 255, 255);

// 白い楕円を描画します
 imagefilledellipse($img, 55, 55, 110, 110, $color); imagefilledellipse(
$img, 55, 55, 40, 40, $color2);

// 画像を出力します
 imagepng($img,"./circle.png"); ?> [/php]

出力結果は[こちら](https://torounit.com/blog/demo/circle.png)

これをWordPressと連携させるのです。うぎゃー。
