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.
A simple example.
- // Analyzation of the MIME type is done during creation.
- if ( $image->mime == 'image/tiff' || $image->mime == 'image/jpeg' )
- {
- // Analyzation of further image data is done during access of the data
- }
- elseif ( $mime !== false )
- {
- echo "Format was detected as {$mime}.\n";
- }
- else
- {
- echo "Unknown photo format.\n";
- }
If you want to manipulate the handlers used by ezcImageAnalyzer, you can do this globally like this:
- // Retreive the predefined handler classes
- foreach ( $handlerClasses as $id => $handlerClass )
- {
- // Unset the ezcImageAnalyzerPhpHandler (do not use that anymore!)
- if ( $handlerClass === 'ezcImageAnalyzerPhpHandler' )
- {
- unset( $handlerClasses[$id] );
- }
- }
- // Set the new collection of handler classes.
- // Somewhere else in the code... This now tries to use your handler in the
- // first place
Or you can define your own handler classes to be used (beware, those must either be already loaded or load automatically on access).
- // Define your onw handler class to be used in the first place and fall back on
- // ImageMagick, if necessary.
- $handlerClasses = array( 'MyOwnHandlerClass', 'ezcImageAnalyzerImagemagickHandler' );
- // Somewehre else in the code... This now tries to use your handler in the
- // first place
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
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
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
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
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
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
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. |