* General class for fetching and parsing EXIF information from images.
*
* Works equally well with either the built in php exif functions (if PHP
- * compiled with exif support) or the (slower) bundled exif library.
+ * compiled with exif support), the Exiftool package (more complete but slower),
+ * or the bundled exif library.
*
* Copyright 2003-2009 The Horde Project (http://www.horde.org/)
*
*/
class Horde_Image_Exif
{
- static public function factory($driver = null)
+ /**
+ * Factory method for instantiating a Horde_Image_Exif object.
+ *
+ * @param string $driver
+ * @param array $params
+ *
+ * @return Horde_Image_Exif
+ */
+ static public function factory($driver = null, $params = array())
{
if (empty($driver) && function_exists('exif_read_data')) {
$driver = 'Php';
$class = 'Horde_Image_Exif_' . $driver;
- return new $class;
+ return new $class($params);
}
/**
* Converts from Intel to Motorola endien. Just reverses the bytes
* (assumes hex is passed in)
*
- * @param $num
- * @return unknown_type
+ * @param $intel
+ *
+ * @return
*/
static public function intel2Moto($intel)
{
}
/**
+ * Obtain an array of supported meta data fields.
+ *
+ * @TODO: This should probably be extended by the subclass?
*
- * @return unknown_type
+ * @return array
*/
static public function getFields()
{
<?php
/**
+ * Base class for Horde_Image_Exif drivers.
*
+ * Copyright 2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Horde_Image
*/
abstract class Horde_Image_Exif_Base
{
- abstract public function getData($image);
+ /**
+ * Instance parameters.
+ *
+ * @var array
+ */
+ protected $_params;
+
+ /**
+ * Optional Logger
+ */
+ protected $_logger;
+
+ /**
+ *
+ * @param $params
+ */
+ public function __construct($params = array())
+ {
+ if (!empty($params['logger'])) {
+ $this->_logger = $params['logger'];
+ unset($params['logger']);
+ }
+ $this->_params = $params;
+ }
/**
*
return round($degs, 6);
}
+ protected function _logDebug($message)
+ {
+ if (!empty($this->_logger)) {
+ $this->_logger->debug($message);
+ }
+ }
+
+ protected function _logErr($message)
+ {
+ if (!empty($this->_logger)) {
+ $this->_logger->err($message);
+ }
+ }
+
+ abstract public function getData($image);
+
+
}
\ No newline at end of file
* Class for dealing with Exif data using a bundled PHP library based on Exifer.
*
*
+ * Copyright 2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Horde_Image
*/
class Horde_Image_Exif_Bundled extends Horde_Image_Exif_Base
{
--- /dev/null
+<?php
+/**
+ * Exiftool driver for reading/writing image meta data
+ *
+ * Copyright 2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Horde_Image
+ */
+class Horde_Image_Exif_Exiftool extends Horde_Image_Exif_Base
+{
+ /**
+ * Path to exiftool binary
+ *
+ * @var string
+ */
+ protected $_exiftool;
+
+ public function __construct($params)
+ {
+ parent::__construct($params);
+ if (!empty($this->_params['exiftool'])) {
+ $this->_exiftool = $this->_params['exiftool'];
+ } else {
+ throw new InvalidArgumentException('Missing required exiftool path');
+ }
+ }
+
+ /**
+ *
+ * @return unknown_type
+ */
+ public function getData($image)
+ {
+ // Request the full stream of meta data in JSON format.
+ $command = '-j ' . $image;
+ $test = $this->_execute($command);
+ $results = json_decode($this->_execute($command));
+ var_dump($results);
+ if ($results instanceof stdClass) {
+ return $results;
+ }
+
+ throw new Horde_Image_Exception('Unknown error running exiftool command.');
+ }
+
+ /**
+ * Executes a exiftool command.
+ *
+ * @param string $command The command to run
+ *
+ * @return mixed The result of the command.
+ */
+ protected function _execute($command)
+ {
+ exec($this->_exiftool . ' ' . escapeshellcmd($command), $output, $retval);
+ if ($retval) {
+ $this->_logErr(sprintf("Error running command: %s"), $command . "\n" . implode("\n", $output));
+ }
+ if (is_array($output)) {
+ $output = implode('', $output);
+ }
+
+ return $output;
+ }
+
+}
\ No newline at end of file
/**
* Exif driver for Horde_Image utilizing PHP's compiled-in exif functions
*
+ * Copyright 2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Horde_Image
*/
class Horde_Image_Exif_Php extends Horde_Image_Exif_Base
{
<file name="Base.php" role="php" />
<file name="Bundled.php" role="php" />
<file name="Php.php" role="php" />
+ <file name="Exiftool.php" role="php" />
</dir> <!-- /Horde/Image/Exif -->
<file name="Effect.php" role="php" />
<file name="Gd.php" role="php" />
<install name="lib/Horde/Image/Exif/Base.php" as="Horde/Image/Exif/Base.php" />
<install name="lib/Horde/Image/Exif/Bundled.php" as="Horde/Image/Exif/Bundled.php" />
<install name="lib/Horde/Image/Exif/Php.php" as="Horde/Image/Exif/Php.php" />
+ <install name="lib/Horde/Image/Exif/Exiftool.php" as="Horde/Image/Exif/Exiftool.php" />
<install name="lib/Horde/Image/Exif.php" as="Horde/Image/Exif.php" />
<install name="lib/Horde/Image/Effect/Border.php" as="Horde/Image/Effect/Border.php" />
<install name="lib/Horde/Image/Effect/Im/DropShadow.php" as="Horde/Image/Effect/Im/DropShadow.php" />