ImageAnalysis: ezcImageAnalyzer
[ ]
[ ]
[ ]
[ ]
[ ]
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.
A simple example.
1. // Analyzation of the MIME type is done during creation.
2. $image = new ezcImageAnalyzer( dirname( __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. // Somewehre 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' );
Member Variables
|
protected mixed |
$availableHandlers
|
|
protected ezcImageAnalyzerData |
$data
Extended data about the image. |
|
protected string |
$filePath
The path of the file to analyze. |
|
protected bool |
$isAnalyzed
Determines whether the image file has been analyzed or not. |
|
protected array(int=>string) |
$knownHandlers
= array( 'ezcImageAnalyzerPhpHandler' => array(),'ezcImageAnalyzerImagemagickHandler'=>array(),)
Collection of known handler classes. Classes are ordered by priority. |
|
protected string |
$mime
The MIME type of the image. |
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. |
|
public mixed |
__get(
$name )
Returns the property $name. |
|
public bool |
__isset(
$name )
Checks if the property $name exist and returns the result. |
|
public void |
__set(
$name, $value )
Sets the property $name to $value. |
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
| Class | 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.
Throws
| Class | Description |
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
| Class | Description |
ezcImageAnalyzerFileNotProcessableException |
If the no handler is capable to analyze the given image file. |
checkHandlers
void checkHandlers(
)
Check all known handlers for availability.
Throws
| Class | Description |
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. |
__get
mixed __get(
string
$name )
Returns the property $name.
Parameters
| Name |
Type |
Description |
$name |
string |
Name of the property to access. |
Throws
| Class | Description |
ezcBasePropertyNotFoundException |
If the property does not exist. |
__isset
bool __isset(
string
$name )
Checks if the property $name exist and returns the result.
Parameters
| Name |
Type |
Description |
$name |
string |
|
__set
void __set(
string
$name, mixed
$value )
Sets the property $name to $value.
Parameters
| Name |
Type |
Description |
$name |
string |
|
$value |
mixed |
|
Throws
| Class | Description |
ezcBasePropertyNotFoundException |
If the property does not exist. |
ezcBasePropertyPermissionException |
If the property cannot be modified. |
Last updated: Fri, 02 Nov 2007