## Apache Zeta Components Manual :: Docs For Class ezcImageAnalyzer

### ImageAnalysis::ezcImageAnalyzer

### Class ezcImageAnalyzer

Class to retreive information about a given image file.

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):

- ezcImageAnalyzerImagemagickHandler, which uses the ImageMagick binary "identify" to collect information about an image.
- ezcImageAnalyzerPhpHandler, which relies on the GD extension and is capable of using the exif extension to determine additional data.

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 ezcImageAnalyzer ( dirname (__FILE__).'/toby.jpg');
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($handlerClassesas$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);
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);
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');

Source for this file: /ImageAnalysis/src/analyzer.php

Version: | //autogentag//

### Properties

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

### Member Variables

protected static array | `$availableHandlers` Available handler classes and their options.
protected static array(string=>mixed) | `$knownHandlers` Collection of known handler classes. Classes are ordered by priority.
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) | `$properties` Container to hold the properties

### Method Summary

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.
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.

### Methods

#### getHandlerClasses

static 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

static 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.

#### __construct

ezcImageAnalyzer __construct( string $file )

Create an image analyzer for the specified file.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$file` | string | The file to analyze.

##### Exceptions:

Type | Description
--- | ---
`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.

##### Exceptions:

Type | Description
--- | ---
`ezcBaseFileIoException` | If an error occurs while the file is read.
`ezcImageAnalyzerFileNotProcessableException` | If the no handler is capable to analyze the given image file.

#### 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.

##### Exceptions:

Type | Description
--- | ---
`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()).

##### Exceptions:

Type | Description
--- | ---
`ezcImageAnalyzerInvalidHandlerException` | If a registered handler class does not exist or does not inherit from ezcImageAnalyzerHandler.

Documentation generated by phpDocumentor 1.4.3