function imagebmp(&$img, $filename = false) { $wid = imagesx($img); $hei = imagesy($img); $wid_pad = str_pad('', $wid % 4, ""); $size = 54 + ($wid + $wid_pad) * $hei * 3; //fixed //prepare & save header $header['identifier'] = 'BM'; $header['file_size'] = dword($size); $header['reserved'] = dword(0); $header['bitmap_data'] = dword(54); $header['header_size'] = dword(40); $header['width'] = dword($wid); $header['height'] = dword($hei); $header['planes'] = word(1); $header['bits_per_pixel'] = word(24); $header['compression'] = dword(0); $header['data_size'] = dword(0); $header['h_resolution'] = dword(0); $header['v_resolution'] = dword(0); $header['colors'] = dword(0); $header['important_colors'] = dword(0); if ($filename) { $f = fopen($filename, "wb"); foreach ($header as $h) { fwrite($f, $h); } //save pixels for ($y = $hei - 1; $y >= 0; $y--) { for ($x = 0; $x < $wid; $x++) { $rgb = imagecolorat($img, $x, $y); fwrite($f, byte3($rgb)); } fwrite($f, $wid_pad); } fclose($f); } else { foreach ($header as $h) { echo $h; } //save pixels for ($y = $hei - 1; $y >= 0; $y--) { for ($x = 0; $x < $wid; $x++) { $rgb = imagecolorat($img, $x, $y); echo byte3($rgb); } echo $wid_pad; } } }
public function __construct($b) { $this->xs = dword($b, 6); $this->ys = dword($b, 10); //printf("Loading map: %03d*%03d\n", $this->xs, $this->ys); $n = $this->xs * $this->ys; $i = 14; $x = 0; $y = 0; $this->m = array(); for ($xy = 0; $xy < $n; $xy++) { $this->m[$x++][$y] = dword($b, $i + 16) == 0 ? true : false; if ($x == $this->xs) { $x = 0; $y++; } $i += 20; } }