imagewbmp

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

説明

bool imagewbmp(GdImage $image, resourcestringnull $file = null, intnull $foreground_color = null)

imagewbmp は、指定した imageWBMP にして出力あるいは保存します。

パラメータ

image

imagecreatetruecolorのような画像作成関数が返す GdImage オブジェクト。

file

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

foreground_color

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

戻り値

成功した場合に true を、失敗した場合に false を返します。

警告

しかしながら、libgd がイメージの出力に失敗した場合、この関数は true を返します。

変更履歴

バージョン 説明
8.0.0 image は、 GdImage クラスのインスタンスを期待するようになりました。 これより前のバージョンでは、有効な gd resource が期待されていました。
8.0.0 foreground_color は、 nullable になりました。

例1 WBMP 画像の出力

<?php
// 空の画像を作成してテキストを追加します
$im imagecreatetruecolor(12020);
$text_color imagecolorallocate($im2331491);
imagestring($im155,  '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(12020);
$text_color imagecolorallocate($im2331491);
imagestring($im155,  'A Simple Text String'$text_color);

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

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

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

<?php
// 空の画像を作成してテキストを追加します
$im imagecreatetruecolor(12020);
$text_color imagecolorallocate($im2331491);
imagestring($im155,  '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($im25500);

imagewbmp($imNULL$foreground_color);

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

参考

  • image2wbmp
  • imagepng
  • imagegif
  • imagejpeg
  • imagetypes