ImageAnalysis
[ ]
[ ]
[ ]
[ ]
[ ]
The ImageAnalysis component allows you to analyze certain image attributes.
ezcImageAnalyzer is the main class for this component. It is responsible for
handling the analysis of image files, as well as caching the results.
The following example simply detects the MIME type of an image and prints it:
- <?php
- require_once 'tutorial_autoload.php';
- $tutorialPath = dirname( __FILE__ );
-
- $image = new ezcImageAnalyzer( "{$tutorialPath}/img/imageanalysis_example_01.jpg" );
-
- echo "Image has MIME type <{$image->mime}>.\n";
- ?>
On line 5, a new ezcImageAnalyzer object is instantiated. This must be done for
each image to be analyzed. In line 7, the MIME type is determined. Here is an
example image including the output:
Image has MIME type <image/jpeg>
Like ezcImageConverter, ezcImageAnalyzer is based on handler classes, which
allow it to utilize different back-ends for image analysis. The currently
implemented handlers are:
- ezcImageAnalyzerPhpHandler
- This uses PHP's getimagesize() function (which does not require the GD
extension!) and can optionally use PHP's Exif extension.
- ezcImageAnalyzerImagemagickHandler
- Here ImageMagick's "identify" program is used.
Both handlers are activated by default and are capable of determining if their
preconditions are fulfilled.
You might need to configure a handler, if for example the path to the
ImageMagick "identify" binary is not available in the $PATH environment
variable. The following example shows how this is possible and what else can be
configured for the handlers:
- <?php
- require_once 'tutorial_autoload.php';
- $tutorialPath = dirname( __FILE__ );
-
- ezcImageAnalyzer::setHandlerClasses(
- array(
- 'ezcImageAnalyzerImagemagickHandler' => array( 'binary' => '/usr/bin/identify' ),
- )
- );
-
- $image = new ezcImageAnalyzer( $tutorialPath.'/img/imageanalysis_example_03.jpg' );
-
- echo "Image data:\n";
- echo "MIME type:\t{$image->mime}\n";
- echo "Width:\t\t{$image->data->width} px\n";
- echo "Height:\t\t{$image->data->height} px\n";
- echo "Filesize:\t{$image->data->size} b\n";
-
- $comment = ( $image->data->comment == '' ) ? 'n/a' : $image->data->comment;
- echo "Comment:\t{$comment}\n";
- ?>
Basically, the code is the same as in example 2, except that ezcImageAnalyzer
is being configured to only use its ImageMagick handler and
not the PHP handler. In addition, the location of the "identify" binary is
explicitly set. See the results below:
Image data:
MIME type: image/jpeg
Width: 320 px
Height: 240 px
Filesize: 26365 b
Comment: San Francisco airport, October 2005.
Last updated: Mon, 21 Dec 2009