Login   Register  
PHP Classes
elePHPant
Icontem

File: example09.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  >  example09.php  >  Download  
File: example09.php
Role: Example script
Content type: text/plain
Description: reading some fields in the GIF header
Class: CFile
Read and write values to binary files
Author: By
Last change:
Date: 2011-08-17 06:32
Size: 3,666 bytes
 

Contents

Class file image Download
<?php // example 01 : simple open and close
      
require_once( "cfile.class.php" );
      
      echo 
"<b>EXAMPLE 09</b>: we read some fields in the GIF header<br><br>" ;
      
$CANDIDATEfile "flowers.gif" ;
      
      
$cfile = new cfile$CANDIDATEfileCFILE_LITTLE_ENDIAN );
      
$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>" ;
           
           
$nbytes // GIF MARKER
           
$READ $cfile->read$nbytesCFILE_TEXT_MODE ) ;
           echo ( 
$READ === false ) ? "CAN'T READ from file ... <b>".$cfile->get_error_string()."</b><br>" "GIF MARKER:<b>$READ</b><br>" ;

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

           
$nbytes // BIT MAPPED
           
$READ $cfile->read$nbytesCFILE_BINARY_INT_MODE ) ;

           
$COLOR_INDEX_BK $cfile->read$nbytesCFILE_BINARY_INT_MODE ) ;
           
$RESERVED $cfile->read$nbytesCFILE_BINARY_INT_MODE ) ;
           
           
$BITS_PER_PIXEL $READ ;
           
                
$COLORS pow2$BITS_PER_PIXEL );
                
$nbytes ;
                
$COLONNE 16 ;
           
                echo 
"<br>
                      <table cellpadding=0 cellspacing=0 valign=\"top\">
                      <tr><td HEIGHT=\"1\"></td></tr>
                      <tr><td COLSPAN=\""
.( $COLONNE )."\">PALETTE - $COLORS colors</td></tr>" ;
           
           
$nbytes // READ PALETTE
           
for( $clr_count $clr_count $COLORS $clr_count++ )
           {
               
$PALETTE_RED $cfile->read$nbytesCFILE_BINARY_INT_MODECFILE_BIG_ENDIAN ) ;
               
$PALETTE_GREEN $cfile->read$nbytesCFILE_BINARY_INT_MODECFILE_BIG_ENDIAN ) ;
               
$PALETTE_BLUE $cfile->read$nbytesCFILE_BINARY_INT_MODECFILE_BIG_ENDIAN ) ;

                    
$BK "rgb( $PALETTE_RED$PALETTE_GREEN$PALETTE_BLUE )" ;
                    
                    
$PALETTEarray[$i] = array( $PALETTE_RED$PALETTE_GREEN$PALETTE_BLUE ); 
                    
                    if ( 
$clr_count $COLONNE == ) echo "<tr>" ;
                    
                    echo 
"<td WIDTH=\"14\" HEIGHT=\"14\" STYLE=\"background-color:$BK\"></td>
                          <td WIDTH=\"1\"></td>" 
;
                              
                    if ( 
$clr_count $COLONNE == ( $COLONNE ) )
                    echo 
"</tr>
                          <tr><td HEIGHT=\"1\"></td></tr>" 
;
           }

                echo 
"</table>" ;

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