GD および Image 関数
PHP Manual

imagewbmp

(PHP 4 >= 4.0.1, PHP 5, PHP 7)

imagewbmp — 画像をブラウザあるいはファイルに出力する

説明

bool imagewbmp ( resource $image [, mixed $to [, int $foreground ]] )

imagewbmp() は、指定した image を WBMP にして出力あるいは保存します。

パラメータ

image

imagecreatetruecolor() のような画像作成関数が返す画像リソース。

to

ファイル保存先のパスあるいはオープン中のリソース (この関数が値を戻した後で自動的にクローズされます)。省略したり NULL を設定したりした場合は、画像ストリームを直接出力します。

foreground

このパラメータで、 前景の色を指定できます。imagecolorallocate() で 取得した ID を使用してください。デフォルトの前景色は黒です。

返り値

成功した場合に TRUE を、失敗した場合に FALSE を返します。

変更履歴

バージョン 説明
5.4.0 ストリームリソースを to に渡せるようになりました。

例

例1 WBMP 画像の出力

<?php
// 空の画像を作成してテキストを追加します
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  'A Simple Text String', $text_color);

// content type ヘッダを設定します - ここでは image/vnd.wap.wbmp
// ヒント: image_type_to_mime_type() で content-types を取得します
header('Content-Type: image/vnd.wap.wbmp');

// 画像を出力します
imagewbmp($im);

// メモリを開放します
imagedestroy($im);
?>

例2 WBMP 画像の保存

<?php
// 空の画像を作成してテキストを追加します
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  'A Simple Text String', $text_color);

// 画像を保存します
imagewbmp($im, 'simpletext.wbmp');

// メモリを開放します
imagedestroy($im);
?>

例3 別の前景での画像の出力

<?php
// 空の画像を作成してテキストを追加します
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  'A Simple Text String', $text_color);

// content type ヘッダを設定します - ここでは image/vnd.wap.wbmp
// ヒント: image_type_to_mime_type() で content-types を取得します
header('Content-Type: image/vnd.wap.wbmp');

// 別の前景色を設定します
$foreground_color = imagecolorallocate($im, 255, 0, 0);

imagewbmp($im, NULL, $foreground_color);

// メモリを開放します
imagedestroy($im);
?>

参考


GD および Image 関数
PHP Manual