Author: Tobias Schlitt
Date: 2006-01-13 19:06:00 +0100 (Fri, 13 Jan 2006)
New Revision: 1847
Log:
- Implemented possibility to provide the "identify" binary path for the
ezcImageAnalyzerImagemagickHandler when using the
ezcImageAnalyzer::setHandlerClasses() method.
Modified:
packages/ImageAnalysis/trunk/src/analyzer.php
packages/ImageAnalysis/trunk/src/handlers/imagemagick.php
packages/ImageAnalysis/trunk/src/handlers/php.php
packages/ImageAnalysis/trunk/src/interfaces/handler.php
packages/ImageAnalysis/trunk/tests/analyzer_test.php
Modified: packages/ImageAnalysis/trunk/src/analyzer.php
===================================================================
--- packages/ImageAnalysis/trunk/src/analyzer.php 2006-01-13 16:45:23 UTC
(rev 1846)
+++ packages/ImageAnalysis/trunk/src/analyzer.php 2006-01-13 18:06:00 UTC
(rev 1847)
@@ -127,8 +127,8 @@
* @var array(int=>string)
*/
protected static $knownHandlers = array(
- 'ezcImageAnalyzerPhpHandler',
- 'ezcImageAnalyzerImagemagickHandler',
+ 'ezcImageAnalyzerPhpHandler' => array(),
+ 'ezcImageAnalyzerImagemagickHandler' => array(),
);
protected static $availableHandlers;
@@ -181,15 +181,16 @@
return;
}
ezcImageAnalyzer::$availableHandlers = array();
- foreach ( ezcImageAnalyzer::$knownHandlers as $handlerClass )
+ foreach ( ezcImageAnalyzer::$knownHandlers as $handlerClass =>
$options )
{
if ( !class_exists( $handlerClass ) || !is_subclass_of(
$handlerClass, 'ezcImageAnalyzerHandler' ) )
{
throw new ezcImageAnalyzerInvalidHandlerException(
$handlerClass );
}
- if ( call_user_func( array( $handlerClass, 'isAvailable') ) )
+ $handler = new $handlerClass( $options );
+ if ( $handler->isAvailable() )
{
- ezcImageAnalyzer::$availableHandlers[] = new $handlerClass;
+ ezcImageAnalyzer::$availableHandlers[] = clone( $handler );
}
}
}
Modified: packages/ImageAnalysis/trunk/src/handlers/imagemagick.php
===================================================================
--- packages/ImageAnalysis/trunk/src/handlers/imagemagick.php 2006-01-13
16:45:23 UTC (rev 1846)
+++ packages/ImageAnalysis/trunk/src/handlers/imagemagick.php 2006-01-13
18:06:00 UTC (rev 1847)
@@ -11,7 +11,19 @@
/**
* Class to retreive information about a given image file.
+ * This is an ezcImageAnalyzerHandler that utilizes ImageMagick to analyze
+ * image files.
*
+ * This ezcImageAnalyzerHandler can be configured using the
+ * Option 'binary', which must be set to the full path of the ImageMagick
+ * "identify" binary. If this option is not submitted to the
+ * [EMAIL PROTECTED] ezcImageAnalyzerHandler::__construct()} method, the
handler will
+ * use just the name of the binary ("identify" on Unix, "identify.exe" on
+ * Windows).
+ *
+ * You can provide the options of the ezcImageAnalyzerImagemagickHandler to
+ * the [EMAIL PROTECTED] ezcImageAnalyzer::setHandlerClasses()}.
+ *
* @package ImageAnalysis
*/
class ezcImageAnalyzerImagemagickHandler extends ezcImageAnalyzerHandler
@@ -24,7 +36,7 @@
*
* @var string
*/
- protected static $binary;
+ protected $binary;
/**
* Indicates if this handler is available.
@@ -35,7 +47,7 @@
*
* @var bool
*/
- protected static $isAvailable;
+ protected $isAvailable;
/**
* Mapping between ImageMagick identification strings and MIME types.
@@ -250,7 +262,7 @@
$command = '-format ' . escapeshellarg( '[%m|%b|%w|%h|%k|%r|%c]*' ) .
' ' . escapeshellarg( $file );
// Execute ImageMagick
- $return = self::runCommand( $command, $outputString, $errorString );
+ $return = $this->runCommand( $command, $outputString, $errorString );
if ( $return !== 0 || $errorString !== '' )
{
throw new ezcImageAnalyzerFileNotProcessableException( $file,
"ImageMagick error: <{$errorString}>." );
@@ -330,7 +342,7 @@
. escapeshellarg( '%[EXIF:DateTime]' )
. ' ' . escapeshellarg( $file );
- $return = self::runCommand( $command, $outputString, $errorString );
+ $return = $this->runCommand( $command, $outputString, $errorString );
if ( $return !== 0 || $errorString !== '' )
{
return;
@@ -348,7 +360,8 @@
* Returns if the handler can analyze a given MIME type.
* This method returns if the driver is capable of analyzing a given MIME
* type. This method should be called before trying to actually analyze an
- * image using the drivers [EMAIL PROTECTED] self::analyzeImage()} method.
+ * image using the drivers [EMAIL PROTECTED]
ezcImageAnalyzerHandler::analyzeImage()}
+ * method.
*
* @param string $mime The MIME type to check for.
* @return bool True if the handler is able to analyze the MIME type.
@@ -364,41 +377,48 @@
*
* @return bool True is the handler is available.
*/
- public static function isAvailable()
+ public function isAvailable()
{
- if ( !isset( ezcImageAnalyzerImagemagickHandler::$isAvailable ) )
+ if ( !isset( $this->isAvailable ) )
{
- ezcImageAnalyzerImagemagickHandler::$isAvailable =
self::checkImagemagick();
+ $this->isAvailable = $this->checkImagemagick();
}
- return ezcImageAnalyzerImagemagickHandler::$isAvailable;
+ return $this->isAvailable;
}
- protected static function checkImagemagick()
+ protected function checkImagemagick()
{
- switch ( PHP_OS )
+ if ( !isset( $this->options['binary'] ) )
{
- case 'Linux':
- case 'Unix':
- case 'FreeBSD':
- case 'MacOS':
- case 'Darwin':
- self::$binary = 'identify';
- break;
- case 'Windows':
- case 'WINNT':
- case 'WIN32':
- self::$binary = 'identify.exe';
- break;
- default:
- throw new ezcImageAnalyzerException(
- 'System <'.PHP_OS.'> not supported by handler
<ezcImageAnalyzerImagemagickHandler>.',
- ezcImageAnalyzerException::HANDLER_NOT_AVAILABLE
- );
- break;
+ switch ( PHP_OS )
+ {
+ case 'Linux':
+ case 'Unix':
+ case 'FreeBSD':
+ case 'MacOS':
+ case 'Darwin':
+ $this->binary = 'identify';
+ break;
+ case 'Windows':
+ case 'WINNT':
+ case 'WIN32':
+ $this->binary = 'identify.exe';
+ break;
+ default:
+ throw new ezcImageAnalyzerException(
+ 'System <'.PHP_OS.'> not supported by handler
<ezcImageAnalyzerImagemagickHandler>.',
+ ezcImageAnalyzerException::HANDLER_NOT_AVAILABLE
+ );
+ break;
+ }
}
+ else
+ {
+ $this->binary = $this->options['binary'];
+ }
// Run "identify" binary without any parameters
- $return = self::runCommand( '', $outputString, $errorString );
+ $return = $this->runCommand( '', $outputString, $errorString );
// Process potential errors
if ( $return != 0 || strlen( $errorString ) > 0 || strpos(
$outputString, 'ImageMagick' ) === false )
@@ -420,9 +440,9 @@
* @param string $errOut The error output.
* @return int The return value of the command (0 on success).
*/
- protected static function runCommand( $parameters, &$stdOut, &$errOut )
+ protected function runCommand( $parameters, &$stdOut, &$errOut )
{
- $command = escapeshellcmd( self::$binary ) . ( $parameters !== '' ? '
' . $parameters : '' );
+ $command = escapeshellcmd( $this->binary ) . ( $parameters !== '' ? '
' . $parameters : '' );
// Prepare to run ImageMagick command
$descriptors = array(
array( 'pipe', 'r' ),
Modified: packages/ImageAnalysis/trunk/src/handlers/php.php
===================================================================
--- packages/ImageAnalysis/trunk/src/handlers/php.php 2006-01-13 16:45:23 UTC
(rev 1846)
+++ packages/ImageAnalysis/trunk/src/handlers/php.php 2006-01-13 18:06:00 UTC
(rev 1847)
@@ -170,7 +170,7 @@
*
* @return bool True is the handler is available.
*/
- public static function isAvailable()
+ public function isAvailable()
{
return function_exists('getimagesize');
}
Modified: packages/ImageAnalysis/trunk/src/interfaces/handler.php
===================================================================
--- packages/ImageAnalysis/trunk/src/interfaces/handler.php 2006-01-13
16:45:23 UTC (rev 1846)
+++ packages/ImageAnalysis/trunk/src/interfaces/handler.php 2006-01-13
18:06:00 UTC (rev 1847)
@@ -43,16 +43,28 @@
*/
const TRANSPARENCY_TRANSLUCENT = 3;
+
/**
+ * Options for the handler.
+ * Ususally this is empty, but some handlers need special options
+ * e.g. [EMAIL PROTECTED] ezcImageAnalyzerImagemagickHandler}.
+ *
+ * @var array
+ */
+ protected $options = array();
+
+ /**
* Create an ezcImageAnalyzerHandler to analyze a file.
- * The constructor may not do anything to keep the instanciation
- * consistant.
+ * The constructor can optionally receive an array of options. Which
+ * options are utilized by the handler depends on it's implementation.
+ * To determine this, please refer to the specific handler.
*
+ * @param array $options Possible options for the handler.
* @throws ezcImageAnalyzerException If the handler is not able to work.
*/
- public final function __construct()
+ public function __construct( array $options = array() )
{
-
+ $this->options = $options;
}
/**
@@ -65,7 +77,7 @@
*
* @return bool True if the handler is available.
*/
- abstract public static function isAvailable();
+ abstract public function isAvailable();
/**
* Analyzes the image type.
Modified: packages/ImageAnalysis/trunk/tests/analyzer_test.php
===================================================================
--- packages/ImageAnalysis/trunk/tests/analyzer_test.php 2006-01-13
16:45:23 UTC (rev 1846)
+++ packages/ImageAnalysis/trunk/tests/analyzer_test.php 2006-01-13
18:06:00 UTC (rev 1847)
@@ -682,13 +682,13 @@
protected function getAnalyzerPhpHandler( $file )
{
- ezcImageAnalyzer::setHandlerClasses( array(
'ezcImageAnalyzerPhpHandler' ) );
+ ezcImageAnalyzer::setHandlerClasses( array(
'ezcImageAnalyzerPhpHandler' => array() ) );
return new ezcImageAnalyzer( $file );
}
protected function getAnalyzerImageMagickHandler( $file )
{
- ezcImageAnalyzer::setHandlerClasses( array(
'ezcImageAnalyzerImagemagickHandler' ) );
+ ezcImageAnalyzer::setHandlerClasses( array(
'ezcImageAnalyzerImagemagickHandler' => array() ) );
return new ezcImageAnalyzer( $file );
}
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components