Path

ez components / documentation / api reference / 2008.2.1 / imageanalysis


eZ Components 2008.2.1

ImageAnalysis: ezcImageAnalyzer

[ Tutorial ] [ Class tree ] [ Element index ] [ ChangeLog ] [ Credits ]

Class: ezcImageAnalyzer

Class to retreive information about a given image file. [source]
This class scans the specified image file and leaves the information available through the public property ezcImageAnalyzer::$data. The information available depends on the handlers used by the ezcImageAnalyzer and the type of image you select. In case the ezcImageAnalyzer does not find a suitable handler to analyze an image, it will throw a ezcImageAnalyzerFileNotProcessableException.
In this package the following handlers are available (in their priority order): For detailed information on the data provided by these handlers, their capabilities on analyzing images and their speciallties, please take a look at their documentation. For general information on handlers, look at ezcImageAnalyzerHandler, ezcImageAnalyzer::getHandlerClasses() and ezcImageAnalyzer::setHandlerClasses().
A simple example.
 1.  // Analyzation of the MIME type is done during creation.
 2.   $image new ezcImageAnalyzerdirname__FILE__ ).'/toby.jpg' );
 3.  
 4.  if $image->mime == 'image/tiff' || $image->mime == 'image/jpeg' )
 5.  {
 6.       // Analyzation of further image data is done during access of the data
 7.             echo 'Photo taken on '.date'Y/m/d, H:i'$image->data->date ).".\n";
 8.  }
 9.  elseif $mime !== false )
10.  {
11.       echo "Format was detected as {$mime}.\n";
12.  }
13.  else
14.  {
15.       echo "Unknown photo format.\n";
16.  }
If you want to manipulate the handlers used by ezcImageAnalyzer, you can do this globally like this:
 1.  // Retreive the predefined handler classes
 2.   $originalHandlers ezcImageAnalyzer::getHandlerClasses();
 3.  foreach $handlerClasses as $id => $handlerClass )
 4.  {
 5.       // Unset the ezcImageAnalyzerPhpHandler (do not use that anymore!)
 6.             if $handlerClass === 'ezcImageAnalyzerPhpHandler' )
 7.       {
 8.           unset$handlerClasses[$id);
 9.       }
10.  }
11.  // Set the new collection of handler classes.
12.   ezcImageAnalyzer::setHandlerClasses$handlerClasses );
13.  
14.  // Somewhere else in the code... This now tries to use your handler in the
15.  // first place
16.   $image new ezcImageAnalyzer'/var/cache/images/toby.jpg' );
Or you can define your own handler classes to be used (beware, those must either be already loaded or load automatically on access).
1.  // Define your onw handler class to be used in the first place and fall back on
2.  // ImageMagick, if necessary.
3.   $handlerClasses array'MyOwnHandlerClass''ezcImageAnalyzerImagemagickHandler' );
4.  ezcImageAnalyzer::setHandlerClasses$handlerClasses );
5.  
6.  // Somewehre else in the code... This now tries to use your handler in the
7.  // first place
8.   $image new ezcImageAnalyzer'/var/cache/images/toby.jpg' );

Properties

ezcImageAnalyzerData read  $data
Extended data about the image.
string read  $mime
The MIME type of the image.

Member Variables

protected array $availableHandlers
Available handler classes and their options.
protected string $filePath
The path of the file to analyze.
protected bool $isAnalyzed
Determines whether the image file has been analyzed or not.

This is used internally.
protected array(string=>mixed) $knownHandlers = array(
'ezcImageAnalyzerPhpHandler' => array(),'ezcImageAnalyzerImagemagickHandler'=>array(),)

Collection of known handler classes. Classes are ordered by priority.
protected array(string=>mixed) $properties
Container to hold the properties

Method Summary

public ezcImageAnalyzer __construct( $file )
Create an image analyzer for the specified file.
public void analyzeImage( )
Analyze the image file.
public void analyzeType( )
Analyze the image file's MIME type.
protected void checkHandlers( )
Check all known handlers for availability.
public static array(string=>array(string=>string)) getHandlerClasses( )
Returns an array of known handler classes.
public static void setHandlerClasses( $handlerClasses )
Set the array of known handlers.

Methods

__construct

ezcImageAnalyzer __construct( string $file )
Create an image analyzer for the specified file.

Parameters

Name Type Description
$file string The file to analyze.

Throws

ClassDescription
ezcBaseFilePermissionException If image file is not readable.
ezcBaseFileNotFoundException If image file does not exist.
ezcImageAnalyzerFileNotProcessableException If the file could not be processed.

analyzeImage

void analyzeImage( )
Analyze the image file.
This method triggers a handler to analyze the given image file for more data.

Throws

ClassDescription
ezcImageAnalyzerFileNotProcessableException If the no handler is capable to analyze the given image file.
ezcBaseFileIoException If an error occurs while the file is read.

analyzeType

void analyzeType( )
Analyze the image file's MIME type.
This method triggers a handler to analyze the MIME type of the given image file.

Throws

ClassDescription
ezcImageAnalyzerFileNotProcessableException If the no handler is capable to analyze the given image file.

checkHandlers

void checkHandlers( )
Check all known handlers for availability.
This method checks all registered handler classes for if the they are available (using ezcImageAnalyzerHandler::isAvailable()).

Throws

ClassDescription
ezcImageAnalyzerInvalidHandlerException If a registered handler class does not exist or does not inherit from ezcImageAnalyzerHandler.

getHandlerClasses

array(string=>array(string=>string)) getHandlerClasses( )
Returns an array of known handler classes.
This method returns an array of available handler classes. The array is indexed by the handler names, which are assigned to an array of options set for this handler.

setHandlerClasses

void setHandlerClasses( $handlerClasses )
Set the array of known handlers.
Sets the available handlers. The array submitted must be indexed by the handler classes names (attention: handler classes must extend ezcImageAnalyzerHandler), assigned to an array of options for this handler. Most handlers don't have any options. Which options a handler may accept depends on the handler implementation.

Parameters

Name Type Description
$handlerClasses array(string=>array(string=>string)) Handlers and options.

Last updated: Mon, 09 Feb 2009