首页 > PHP

[GD]生成bmp格式的图片(imagebmp)

时间:2010-08-13 07:24:03  作者:chinaitlab  我要投稿
Linux初探欢迎您的投稿,投放方法请点击这里查看,我们会定期赠送精美小礼品给优秀的投稿作者。海纳百川 取则行远!LinuxGoo欢迎您的到来。
GD库里没有生成bmp图片的函数,所以自己写了一个,这个函数尚有一个压缩算法没有写,不过已经够用了。需要的同学可以看看。int imagebmp ( resource image [, string ......

$colors = imagecolorsforindex($im, $index);

if ($bit == 16)
{
$bin = 0 << $bit;

$bin |= ($colors['red'] >> 3) << 10;
$bin |= ($colors['green'] >> 3) << 5;
$bin |= $colors['blue'] >> 3;

$bmp_data .= pack("v", $bin);
}
else
{
$bmp_data .= pack("c*", $colors['blue'], $colors['green'], $colors['red']);
}

// todo: 32bit;
}

$bmp_data .= $extra;
}

$size_quad = 0;
$size_data = strlen($bmp_data);
$colors_num = 0;
}

// 位图文件头
$file_header = "BM" . pack("V3", 54 $size_quad $size_data, 0, 54 $size_quad);

// 位图信息头
$info_header = pack("V3v2V*", 0x28, $width, $height, 1, $bit, $compression, $size_data, 0, 0, $colors_num, 0);

// 写入文件
if ($filename != '')
{
$fp = fopen("test.bmp", "wb");

fwrite($fp, $file_header);
fwrite($fp, $info_header);
fwrite($fp, $rgb_quad);
fwrite($fp, $bmp_data);
fclose($fp);

return 1;
}

// 浏览器输出
header("Content-Type: image/bmp");
echo $file_header . $info_header;
echo $rgb_quad;
echo $bmp_data;

return 1;
}
参考资料:BMP文件格式分析 (出处没有找到…)

原创文章,转载请注明出处。

出处:http://www.ugia.cn/?p=96

如果您需转载 [GD]生成bmp格式的图片(imagebmp),请注明来自LinuxGoo.com,其版权归原作者所有。请广大网友留言时遵纪守法,使用文明用语。如果您在应用中有什么问题,请在下面留言,我们会尽快解答。
来顶一下
近回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
相关文章
栏目热门