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
3/3 首页 上一页 1 2 3 |