ImageClass

The ImageClass is an extension of the FileUploader class. All methods belonging to the FileUploader can be applied on the ImageClass. Other available methods are:

For the purpose of this documentation we shall be using the following data

TEST DATA
 
    $_FILES['name']  = 'Foo'; 
    $_FILES['type']  = 'image/png'; 
    $_FILES['size']  = 5000000; //5mb
    $_FILES['tmp_name']   = '/tmp/files/image.png'; 
    $_FILES['error'] = ''; 

                                

initializing class
The file uploader class can be easily initialized as shown below.

Sample: Initializing ImageClass
  $ImageClass  = new ImageClass;
                                        

Syntax: start
  $ImageClass->start($files, $type);
    
    where:
        
     $files: $_FILES or files data array
     $type: type of file. options [file|image]. An option 'image' allows internal processing of images supplied.
    
                                        
We shall be looking at a series of examples below.
Example: setting files
  $ImageClass->start($_FILES); // set files for upload

  $ImageClass->start($_FILES, 'image'); // set image files for upload

  $destination = "images/";

  if( $ImageClass->uploadFiles(['jpg']) ) {
      $newFileName = $ImageClass->newfile;
  }else{
      $newFileName = '';
  }

  $newFilePath = $destination.'/'.$newFileName;
                                

setImage
The setImage() sets an image for processing

Syntax: setImage
  $ImageClass->setImage($path); 
    
    where:
        
      $path: path of image
    
                                
Example
  $ImageClass->setImage($newFilePath);                         
                                

setWidth
The setwidth() sets the output width of an image

Syntax: setWidth
  $ImageClass->width($width, $height, $quality, $fileOut); 
    
    where:
        
      $width: image width in pixels
      $height: image height in pixels
      $quality: optional image quality from 0 - 9. Nine is the maximum.
      $fileOut: optional output file name.
    
                                
Example: setWidth
  $ImageClass->setWidth(500, 500, 9);                         
                                

resizeImage
This method returns is used to resize an image.

Syntax: resizeImage
  $ImageClass->resizeImage();  // sets image class activity 
                                        
Example: resizeImage
  $ImageClass->setImage($newFilePath);
  $ImageClass-setWidth(500, 500, 9);
  $ImageClass->resizeImage();
                                        

runImage
This method returns the type of current file set.

Syntax: runImage
  $ImageClass->runImage();  // executes the activity declared. 
                                        
Example: runImage
  $ImageClass->setImage($newFilePath);
  $ImageClass-setWidth(500, 500, 9);
  $ImageClass->resizeImage();
  $ImageClass->runImage(); // executes the image resize previously declared
                                        

imageDisplay
This method displays the processed image to the screen using the html img tag.

Syntax: imageDisplay
  $ImageClass->imageDisplay();  // prints the image to screen 
                                        
Example: imageDisplay
    
  $ImageClass->setImage($newFilePath);
  $ImageClass-setWidth(500, 500, 9);
  $ImageClass->resizeImage();
    
  if($ImageClass->runImage()) {

      echo( $ImageClass->imageDisplay() ); // displays array data of file. 

  }
                                        

imageDelete
This method safely deletes an image if it exists without throwing an error. It returns true if image was deleted and false if the image was not able to delete or does not exists.

Syntax: imageDelete
  $ImageClass->imageDelete($path);  // returns true or false. 
    
    where : 

       $path: Optional relative path of image. If not provided, uses relative path defined in setImage() method.
    
                                        
Example: imageDelete
  $ImageClass->setImage($newFilePath);   set image relative path 

  if( $ImageClass->imageDelete() ) {

      //image deleted successfully

  }
                                        

check_jpeg
This method tries to detect if a jpeg image is bad.

Syntax: check_jpeg
  $ImageClass->check_jpeg($filepath, $fix);  // returns true or false 
    
    where : 
        
       $filepath: path of image file 
       $fix: a bool of true tries to fix the image if possible.
    
                                        
Example: check_jpeg
  if( $ImageClass->check_jpeg($newFilePath) ) {

      jpeg file seems okay.

  }
 
                                        

newdata
This method returns the data for current processed file.

Syntax: newData
  $ImageClass->newData();  //  returns array data of valid file or empty array 
                                        
Example: newData
  $ImageClass->setImage($newFilePath);
  $ImageClass-setWidth(500, 500, 9);
  $ImageClass->resizeImage();
    
  if($ImageClass->runImage()) {

      var_dump( $ImageClass->newData() ); // displays array data of file. 

  }
                                      

uniqueFile
This function directs the image class to destroy previous activity

Syntax: imageDestroy
  $ImageClass->imageDestroy();
                                    
Example: imageDestroy
  $ImageClass->setImage($newFilePath);
  $ImageClass-setWidth(500, 500, 9);
  $ImageClass->resizeImage();
  
  if($ImageClass->runImage()) {

     $data = $ImageClass->newData();
     $ImageClass->imageDestroy();

  }