Image_WBMP
[ class tree: Image_WBMP ] [ index: Image_WBMP ] [ all elements ]

Source for file WBMP.php

Documentation is available at WBMP.php

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
  4. // +----------------------------------------------------------------------+
  5. // | PHP version 4                                                        |
  6. // +----------------------------------------------------------------------+
  7. // | Copyright (c) 1997-2002 The PHP Group                                |
  8. // +----------------------------------------------------------------------+
  9. // | This source file is subject to version 2.0 of the PHP license,       |
  10. // | that is bundled with this package in the file LICENSE, and is        |
  11. // | available at through the world-wide-web at                           |
  12. // | http://www.php.net/license/2_02.txt.                                 |
  13. // | If you did not receive a copy of the PHP license and are unable to   |
  14. // | obtain it through the world-wide-web, please send a note to          |
  15. // | license@php.net so we can mail you a copy immediately.               |
  16. // +----------------------------------------------------------------------+
  17. // | Authors: Evgeny Stepanischev <bolk@lixil.ru>                         |
  18. // +----------------------------------------------------------------------+
  19. // Project home page (Russian): http://bolk.exler.ru/files/monobmp/
  20. //
  21. // $Id$
  22.  
  23.  
  24. require_once 'Image/XBM.php';
  25.  
  26. class Image_WBMP extends Image_XBM
  27. {
  28.     function Image_WBMP()
  29.     {
  30.         parent::Image_XBM();
  31.     }
  32.  
  33.     /**
  34.      * Output image to browser or file
  35.      *
  36.      * @param string $filename (optional) filename for output
  37.      * @return bool PEAR_Error or true
  38.      * @access public
  39.      */
  40.     function output($filename = false)
  41.     {
  42.  
  43.         // Header
  44.         $s "\0\0";
  45.  
  46.         // width, height
  47.         $s.= chr($this->_sx).chr($this->_sy);
  48.  
  49.         $wx ceil($this->_sx / 8);
  50.  
  51.         // Prepare image data
  52.         for ($y $this->_sy - 1; $y >= 0; --$y{
  53.             for ($x = 0; $x $wx; ++$x{
  54.                 $s .= chr($this->_image[$x][$y]);
  55.             }
  56.         }
  57.  
  58.  
  59.         if ($filename === false{
  60.             echo $s;
  61.         else {
  62.             if ($fp fopen($filename'w')) {
  63.                 flock($fpLOCK_EX);
  64.  
  65.                 fwrite($fp$s);
  66.                 fclose($fp);
  67.             else {
  68.                 return PEAR::raiseError('Cannot open file for writing.'5);
  69.             }
  70.         }
  71.         return true;
  72.     }
  73.  
  74.     /**
  75.      * Create a new image from XBM file or URL
  76.      *
  77.      * @param string $filename XBM file name or URL
  78.      * @return mixed PEAR_error or true for success
  79.      * @access public
  80.      */
  81.     function createFromFile($filename)
  82.     {
  83.         $fp fopen($filename'r');
  84.         @flock ($fpLOCK_SH);
  85.  
  86.         if (!is_resource($fp)) {
  87.             return PEAR::raiseError('Cannot open file.'4);
  88.         }
  89.  
  90.         // WBMP header
  91.         $sign fread($fp2);
  92.         if ($sign <> "\0\0"{
  93.             return PEAR::raiseError('Invalid WBMP file type.'5);
  94.         }
  95.  
  96.         // width, height
  97.         $width  ord(fread($fp1));
  98.         $height ord(fread($fp1));
  99.  
  100.         // Read the picture
  101.         $sx ceil($width / 8);
  102.  
  103.         // Fill image by bitmap data
  104.         for ($y $height - 1; $y >= 0; --$y{
  105.             for ($x = 0; $x $sx; ++$x{
  106.                 $this->_image[$x][$yord(fread($fp1));
  107.             }
  108.         }
  109.  
  110.  
  111.         fclose($fp);
  112.     }
  113. }
  114. ?>

Documentation generated on Mon, 11 Mar 2019 14:36:33 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.