001.
<?
002.
header(
"Content-type: image/png"
);
003.
header(
"Content-Disposition: attachment; filename=winofsql.png"
);
004.
header(
"Expires: Wed, 31 May 2000 14:59:58 GMT"
);
005.
006.
$im
= ImageCreateFromBMP(
"winofsql.bmp"
);
007.
imagepng(
$im
);
008.
imagedestroy(
$im
);
009.
010.
011.
012.
013.
014.
function
ImageCreateFromBMP(
$filename
)
015.
{
016.
017.
if
(!
$f1
=
fopen
(
$filename
,
"rb"
))
return
FALSE;
018.
019.
020.
$FILE
= unpack(
"vfile_type/Vfile_size/Vreserved/Vbitmap_offset"
,
fread
(
$f1
,14));
021.
if
(
$FILE
[
'file_type'
] != 19778)
return
FALSE;
022.
023.
024.
$BMP
= unpack(
'Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel'
.
025.
'/Vcompression/Vsize_bitmap/Vhoriz_resolution'
.
026.
'/Vvert_resolution/Vcolors_used/Vcolors_important'
,
fread
(
$f1
,40));
027.
$BMP
[
'colors'
] = pow(2,
$BMP
[
'bits_per_pixel'
]);
028.
if
(
$BMP
[
'size_bitmap'
] == 0)
$BMP
[
'size_bitmap'
]
029.
=
$FILE
[
'file_size'
] -
$FILE
[
'bitmap_offset'
];
030.
$BMP
[
'bytes_per_pixel'
] =
$BMP
[
'bits_per_pixel'
]/8;
031.
$BMP
[
'bytes_per_pixel2'
] =
ceil
(
$BMP
[
'bytes_per_pixel'
]);
032.
$BMP
[
'decal'
] = (
$BMP
[
'width'
]*
$BMP
[
'bytes_per_pixel'
]/4);
033.
$BMP
[
'decal'
] -=
floor
(
$BMP
[
'width'
]*
$BMP
[
'bytes_per_pixel'
]/4);
034.
$BMP
[
'decal'
] = 4-(4*
$BMP
[
'decal'
]);
035.
if
(
$BMP
[
'decal'
] == 4)
$BMP
[
'decal'
] = 0;
036.
037.
038.
$PALETTE
=
array
();
039.
if
(
$BMP
[
'colors'
] < 16777216)
040.
{
041.
$PALETTE
= unpack(
'V'
.
$BMP
[
'colors'
],
fread
(
$f1
,
$BMP
[
'colors'
]*4));
042.
}
043.
044.
045.
$IMG
=
fread
(
$f1
,
$BMP
[
'size_bitmap'
]);
046.
$VIDE
=
chr
(0);
047.
048.
$res
= imagecreatetruecolor(
$BMP
[
'width'
],
$BMP
[
'height'
]);
049.
$P
= 0;
050.
$Y
=
$BMP
[
'height'
]-1;
051.
while
(
$Y
>= 0)
052.
{
053.
$X
=0;
054.
while
(
$X
<
$BMP
[
'width'
])
055.
{
056.
if
(
$BMP
[
'bits_per_pixel'
] == 24)
057.
$COLOR
= unpack(
"V"
,
substr
(
$IMG
,
$P
,3).
$VIDE
);
058.
elseif
(
$BMP
[
'bits_per_pixel'
] == 16)
059.
{
060.
$COLOR
= unpack(
"n"
,
substr
(
$IMG
,
$P
,2));
061.
$COLOR
[1] =
$PALETTE
[
$COLOR
[1]+1];
062.
}
063.
elseif
(
$BMP
[
'bits_per_pixel'
] == 8)
064.
{
065.
$COLOR
= unpack(
"n"
,
$VIDE
.
substr
(
$IMG
,
$P
,1));
066.
$COLOR
[1] =
$PALETTE
[
$COLOR
[1]+1];
067.
}
068.
elseif
(
$BMP
[
'bits_per_pixel'
] == 4)
069.
{
070.
$COLOR
= unpack(
"n"
,
$VIDE
.
substr
(
$IMG
,
floor
(
$P
),1));
071.
if
((
$P
*2)%2 == 0)
$COLOR
[1] = (
$COLOR
[1] >> 4) ;
072.
else
$COLOR
[1] = (
$COLOR
[1] & 0x0F);
073.
$COLOR
[1] =
$PALETTE
[
$COLOR
[1]+1];
074.
}
075.
elseif
(
$BMP
[
'bits_per_pixel'
] == 1)
076.
{
077.
$COLOR
= unpack(
"n"
,
$VIDE
.
substr
(
$IMG
,
floor
(
$P
),1));
078.
if
((
$P
*8)%8 == 0)
$COLOR
[1] =
$COLOR
[1] >>7;
079.
elseif
((
$P
*8)%8 == 1)
$COLOR
[1] = (
$COLOR
[1] & 0x40)>>6;
080.
elseif
((
$P
*8)%8 == 2)
$COLOR
[1] = (
$COLOR
[1] & 0x20)>>5;
081.
elseif
((
$P
*8)%8 == 3)
$COLOR
[1] = (
$COLOR
[1] & 0x10)>>4;
082.
elseif
((
$P
*8)%8 == 4)
$COLOR
[1] = (
$COLOR
[1] & 0x8)>>3;
083.
elseif
((
$P
*8)%8 == 5)
$COLOR
[1] = (
$COLOR
[1] & 0x4)>>2;
084.
elseif
((
$P
*8)%8 == 6)
$COLOR
[1] = (
$COLOR
[1] & 0x2)>>1;
085.
elseif
((
$P
*8)%8 == 7)
$COLOR
[1] = (
$COLOR
[1] & 0x1);
086.
$COLOR
[1] =
$PALETTE
[
$COLOR
[1]+1];
087.
}
088.
else
089.
return
FALSE;
090.
imagesetpixel(
$res
,
$X
,
$Y
,
$COLOR
[1]);
091.
$X
++;
092.
$P
+=
$BMP
[
'bytes_per_pixel'
];
093.
}
094.
$Y
--;
095.
$P
+=
$BMP
[
'decal'
];
096.
}
097.
098.
099.
fclose(
$f1
);
100.
101.
return
$res
;
102.
}
103.
?>