GD库里没有生成bmp图片的函数,所以自己写了一个,这个函数尚有一个压缩算法没有写,不过已经够用了。需要的同学可以看看。 int imagebmp ( resource image [, string filename [, int $bit [, int compression]]] ) $im: 图像资源 注意:这个函数仍然需要GD库的支持。 Demo: $im = imagecreatefrompng("test.png"); /**
$filename: 如果要另存为文件,请指定文件名,为空则直接在浏览器输出
$bit: 图像质量(1、4、8、16、24、32位)
$compression: 压缩方式,0为不压缩,1使用RLE8压缩算法进行压缩
imagebmp($im);
imagedestroy($im);
Source:
* 创建bmp格式图片
*
* @author: legend(legendsky@hotmail.com)
* @link: http://www.ugia.cn/?p=96
* @description: create Bitmap-File with GD library
* @version: 0.1
*
* @param resource $im 图像资源
* @param string $filename 如果要另存为文件,请指定文件名,为空则直接在浏览器输出
* @param integer $bit 图像质量(1、4、8、16、24、32位)
* @param integer $compression 压缩方式,0为不压缩,1使用RLE8压缩算法进行压缩
*
* @return integer
*/
function imagebmp(&$im, $filename = , $bit = 8, $compression = 0)
{
if (!in_array($bit, array(1, 4, 8, 16, 24, 32)))
{
$bit = 8;
}
else if ($bit == 32) // todo:32 bit
{
$bit = 24;
}
$bits = pow(2, $bit);
// 调整调色板
imagetruecolortopalette($im, true, $bits);
$width = imagesx($im);
$height = imagesy($im);
$colors_num = imagecolorstotal($im);
if ($bit {
// 颜色索引
$rgb_quad = ;
for ($i = 0; $i {
$colors = imagecolorsforindex($im, $i);
$rgb_quad .= chr($colors[blue]) . chr($colors[green]) . chr($colors[red]) . "";
}
// 位图数据
$bmp_data = ;
// 非压缩
if ($compression == 0 || $bit {
if (!in_array($bit, array(1, 4, 8)))
{
$bit = 8;
}
$compression = 0;
// 每行字节数必须为4的倍数,补齐。
$extra = ;
$padding = 4 - ceil($width / (8 / $bit)) % 4;
if ($padding % 4 != 0)
{
$extra = str_repeat("", $padding);
}
for ($j = $height - 1; $j >= 0; $j --)
{
$i = 0;
while ($i {
$bin = 0;
$limit = $width - $i
for ($k = 8 - $bit; $k >= $limit; $k -= $bit)
{
$index = imagecolorat($im, $i, $j);
$bin |= $index $i ++;
}
$bmp_data .= chr($bin);
}
$bmp_data .= $extra;
}
}
// RLE8 压缩
else if ($compression == 1 && $bit == 8)
{
for ($j = $height - 1; $j >= 0; $j --)
{
$last_index = "";
$same_num = 0;
for ($i = 0; $i {
$index = imagecolorat($im, $i, $j);
if ($index !== $last_index || $same_num > 255)
&nb

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SublimeText3漢化版
中文版,非常好用

Atom編輯器mac版下載
最受歡迎的的開源編輯器

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

禪工作室 13.0.1
強大的PHP整合開發環境

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中