[PHP-users 29877] Bitmapファイルの作成について

木村 幸司 kimura @ bruno.co.jp
2006年 7月 25日 (火) 13:03:03 JST


はじめまして。木村と申します。


サーバOS:Redhat Linux 9
WEBサーバ:Apache/2.0.40
PHP:4.4.1
 GD Support:enabled
 GD Version:bundled (2.0.28 compatible)
 FreeType Support:enabled
 FreeType Linkage:with freetype
 GIF Read Support:enabled
 GIF Create Support:enabled
 JPG Support:enabled
 PNG Support:enabled
 WBMP Support:enabled
 XBM Support:enabled


Spreadsheet_Excel_Writerでエクセルファイルに画像を挿入したいので 
すが、
BMPファイルがうまく作成できず、困っています。
JPEGやGIFのファイルをExcelに直接挿入できる方法があれ 
ば、それでも構いません。
ご指導いただけないでしょうか。宜しくお願い致します。

========== 以下、ソースの一部 ==========

$xls = new Spreadsheet_Excel_Writer();
$xls->send('test.xls');

$img_source = "test.jpg";
$img_dest = "test.bmp";
$imgInput = imagecreatefromjpeg($img_source);
list($w,$h) = getimagesize($img_source);
$imgOutput = imagecreatetruecolor($w,$h);
imagepalettecopy($imgOutput,$imgInput);
imagecopyresampled($imgOutput,$imgInput,0,0,0,0,$w,$h,$w,$h);
image2wbmp($imgOutput,$img_dest);
imagedestroy($imgOutput);
imagedestroy($imgInput);

$xlsSheet->insertBitmap(0,0,$img_dest);
$xls->close();

========== ソースここまで ==========

エクセルファイルはちゃんと作成でき、画像以外のデータはちゃんと表 
示されますが、
画像が表示されません。

手元のBMPファイルをサーバにアップして、それをinsertBitmap 
()したらうまくいくので、
image2wbmp()が正しく動作していないと思います。ちなみにimagewbmp 
()も試してみましたが、
だめでした。というかこの両者の違いがわかりません。
ファイルは作成されますが、元のファイルがどんなサイズでも 
11.1KBの壊れたファイルが作成されます。
image2wbmp()の代わりにimagejpeg()で直接ストリームに出力す 
ると、ブラウザにちゃんと表示されるので、
imagecopyresampled()までの処理は正常に動作していると思われます。

以上、宜しくお願い致します。


BRUNO Systems Inc.
木村 幸司
kimura @ bruno.co.jp


PHP-users メーリングリストの案内