";
$i=0; $ch=array();
while ($i<14) {
$ch[$i]=ord(fgetc($in)); echo $ch[$i]." "; $i++;
}
echo "
";
$filesize=$ch[4]*65536+$ch[3]*56+$ch[2]; $offset=$ch[11]*256+$ch[10];
echo "file size, offset to image: ".$filesize." ".$offset."
";
echo "file information:
";
$i=0;
while ($i<48) { // Read to last byte before start of image.
$ch[$i]=ord(fgetc($in)); echo $ch[$i]." "; $i++;
}
echo "
";
$wt=$ch[6]*65536+$ch[5]*256+$ch[4]; $ht=$ch[10]*65536+$ch[9]*256+$ch[8];
echo "image width, height, size: ".$wt." ".$ht." ".($wt*$ht)."
";
echo "image size from header: ".($ch[22]*65536+$ch[21]*256+$ch[20])."
";
echo "bits per pixel: ".$ch[14]."
";
// Read file, one row at a time.
$w=0; $b=0;
$w=0; $b=0;
for ($r=1; $r<=$ht; $r++) {
for ($c=1; $c<=$wt/8; $c++) {
$ch=fgetc($in); // Read the byte and convert to unsigned integer.
// echo ord($ch)." ";
$num=ord($ch); $bit=1;
for ($m=0; $m<=7; $m++) {
if (($num & $bit) == $bit) $w++; else $b++; $bit*=2;
}
}
$ch=fgetc($in); // Read end-of-row byte.
// echo "EOR ".ord($ch)."
";
}
echo "black, white pixels: ".$b." ".$w."
";
fclose($in);
?>