Source for file MonoBMP.php
Documentation is available at MonoBMP.php
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Evgeny Stepanischev <bolk@lixil.ru> |
// +----------------------------------------------------------------------+
// Project home page (Russian): http://bolk.exler.ru/files/monobmp/
require_once 'Image/XBM.php';
class Image_MonoBMP extends Image_XBM
* Output image to browser or file
* @param string $filename (optional) filename for output
* @return bool PEAR_Error or true
function output ($filename = false )
$wx = ceil($this->_sx / 8 );
for ($y = $this->_sy - 1; $y >= 0; -- $y) {
for ($x = 0; $x < $wx; ++ $x) {
$s .= chr($this->_bitrev ($this->_image[$x][$y]));
$size, // picture size (bytes)
0xB12 , // X pixels per meter
0xB12 , // Y pixels per meter
0 , // color used (0 mean "all")
0 // important colors (all)
$header = pack('V', strlen($header) + 4 ) . $header;
// Adding color table (white and black colors)
$color = "\xFF\xFF\xFF\0\0\0\0\0";
$main = pack('vvV', 0 , 0 , 0x3E );
// Build header and bitmap data
$s = $main. $header. $color. $s. "\0";
if ($filename === false ) {
if ($fp = fopen($filename, 'w')) {
return PEAR ::raiseError ('Cannot open file for writing.', 5 );
* Create a new image from XBM file or URL
* @param string $filename XBM file name or URL
* @return mixed PEAR_error or true for success
function createFromFile ($filename)
$fp = fopen($filename, 'r');
return PEAR ::raiseError ('Cannot open file.', 4 );
// Bitmap magick signature
return PEAR ::raiseError ('Invalid BMP file.', 5 );
// Check if bitmap is b/w
return PEAR ::raiseError ('Invalid BMP file.', 5 );
$this->create ($width, $height);
// Skip rest of the header
// Fill image by bitmap data
for ($y = $height - 1; $y >= 0; -- $y) {
for ($x = 0; $x < $sx; ++ $x) {
$this->_image[$x][$y] = $this->_bitrev (ord(fread($fp, 1 )));
* @param int $num number for reverse
* @return int bit reversed number
for ($i = $r = 0; $i<8; $i++ ) {
Documentation generated on Mon, 11 Mar 2019 14:12:47 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|