Login   Register  
PHP Classes
elePHPant
Icontem

File: example05.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of zandor  >  CFile  >  example05.php  >  Download  
File: example05.php
Role: Example script
Content type: text/plain
Description: reading some fields in the BITMAP (.BMP) header
Class: CFile
Read and write values to binary files
Author: By
Last change:
Date: 3 years ago
Size: 4,167 bytes
 

Contents

Class file image Download
<?php // example 01 : simple open and close
      
echo "<b>EXAMPLE 05</b>: we read some fields in the BITMAP (.BMP) header<br><br>" ;

      require_once( 
"cfile.class.php" );
      
      
$CANDIDATEfile "andromeda.bmp" ;
      
      
$cfile = new cfile$CANDIDATEfile );
      
$bOPEN $cfile->openCFILE_READ_MODE );
      
$bERR $cfile->is_error() ;
      
      if ( 
$bOPEN && !$bERR // you can check open return value or internal error for safe operation
      
{
           echo 
"OPEN FILE <b>$CANDIDATEfile</b> : SUCCESS<br>" ;
           
           echo 
"FILE SIZE : ".( filesize$CANDIDATEfile ) )." bytes<br>" ;
           
           
$bBEGIN $cfile->move_to_beginning();
           echo ( 
$bBEGIN ) ? "OK MOVE TO BEGINNING ...<br>" "CAN'T MOVE TO THE BEGINNING ...<br>" ;

           echo 
"<br>READING <b>BITMAP FILE HEADER</b><br>" ;
           
           
$nbytes // BM MARKER
           
$READ $cfile->read$nbytesCFILE_TEXT_MODE ) ;
           echo ( 
$READ === false ) ? "CAN'T READ from file ... <b>".$cfile->get_error_string()."</b><br>" "BITMAP MARKER ($nbytes):<b>$READ</b><br>" ;
           
           
$nbytes // SIZE OF BITMAP
           
$READ $cfile->read$nbytesCFILE_BINARY_INT_MODE ) ;
           echo ( 
$READ === false ) ? "CAN'T READ from file ... <b>".$cfile->get_error_string()."</b><br>" "SIZE OF BITMAP ($nbytes):<b>$READ</b><br>" ;

           
$nbytes // RESERVED (0)
           
$READ $cfile->read$nbytesCFILE_BINARY_INT_MODE ) ;
           echo ( 
$READ === false ) ? "CAN'T READ from file ... <b>".$cfile->get_error_string()."</b><br>" "RESERVED ($nbytes):<b>$READ</b><br>" ;

           
$nbytes // RESERVED (1)
           
$READ $cfile->read$nbytesCFILE_BINARY_INT_MODE ) ;
           echo ( 
$READ === false ) ? "CAN'T READ from file ... <b>".$cfile->get_error_string()."</b><br>" "RESERVED ($nbytes):<b>$READ</b><br>" ;

           
$nbytes // OFFSET BITS TO BITMAP DATA
           
$READ $cfile->read$nbytesCFILE_BINARY_INT_MODE ) ;
           echo ( 
$READ === false ) ? "CAN'T READ from file ... <b>".$cfile->get_error_string()."</b><br>" "OFFSET BITS TO BITMAP DATA ($nbytes):<b>$READ</b><br>" ;

           echo 
"<br>READING <b>BITMAP INFO HEADER</b><br>" ;

           
$nbytes // size of the BITMAPINFOHEADER structure, in bytes
           
$READ $cfile->read$nbytesCFILE_BINARY_INT_MODE ) ;
           echo ( 
$READ === false ) ? "CAN'T READ from file ... <b>".$cfile->get_error_string()."</b><br>" "size of the BITMAPINFOHEADER structure, in bytes ($nbytes):<b>$READ</b><br>" ;

           
$nbytes // WIDTH
           
$READ $cfile->read$nbytesCFILE_BINARY_INT_MODE ) ;
           echo ( 
$READ === false ) ? "CAN'T READ from file ... <b>".$cfile->get_error_string()."</b><br>" "IMAGE WIDTH ($nbytes):<b>$READ</b><br>" ;

           
$nbytes // HEIGHT
           
$READ $cfile->read$nbytesCFILE_BINARY_INT_MODE ) ;
           echo ( 
$READ === false ) ? "CAN'T READ from file ... <b>".$cfile->get_error_string()."</b><br>" "IMAGE HEIGHT ($nbytes):<b>$READ</b><br>" ;

           
$nbytes // PLANES
           
$READ $cfile->read$nbytesCFILE_BINARY_INT_MODE ) ;
           echo ( 
$READ === false ) ? "CAN'T READ from file ... <b>".$cfile->get_error_string()."</b><br>" "PLANES ($nbytes):<b>$READ</b><br>" ;

           
$nbytes // BITS per PIXEL
           
$READ $cfile->read$nbytesCFILE_BINARY_INT_MODE ) ;
           echo ( 
$READ === false ) ? "CAN'T READ from file ... <b>".$cfile->get_error_string()."</b><br>" "BITS per PIXEL ($nbytes):<b>$READ</b><br>" ;

           
$nbytes // COMPRESSION
           
$READ $cfile->read$nbytesCFILE_BINARY_INT_MODE ) ;
           echo ( 
$READ === false ) ? "CAN'T READ from file ... <b>".$cfile->get_error_string()."</b><br>" "COMPRESSION ($nbytes):<b>$READ</b><br>" ;

           echo 
"<br>" ;
           echo ( 
$cfile->close() ) ? "CLOSE FILE <b>$CANDIDATEfile</b> : SUCCESS" $cfile->get_error_string() ;
      }
      else echo 
$cfile->get_error_string() ;
?>