imagecreate
(PHP 4, PHP 5, PHP 7)
imagecreate — パレットを使用する新規画像を作成する
説明
imagecreate
( int $width
, int $height
) : resource
imagecreate() は、 指定した大きさの空の画像を表す画像 ID を返します。
一般に、imagecreate() よりは imagecreatetruecolor() を使うことを推奨します。 より高品質な画像処理ができるからです。パレット形式の画像を出力したい場合は、 imagepng() や imagegif() で画像を保存する直前に imagetruecolortopalette() を呼ばなければいけません。
パラメータ
width
- 画像の幅。
height
- 画像の高さ。
返り値
成功した場合に画像リソース ID、エラー時に false
を返します。
例
例1 新しい GD 画像ストリームの作成および画像の出力
<?phpheader("Content-Type: image/png");$im = @imagecreate(110, 20) or die("Cannot Initialize new GD image stream");$background_color = imagecolorallocate($im, 0, 0, 0);$text_color = imagecolorallocate($im, 233, 14, 91);imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);imagepng($im);imagedestroy($im);?>
上の例の出力は、 たとえば以下のようになります。