EZ-Components
@@ -0,0 +1,16 @@
|
||||
CREDITS
|
||||
=======
|
||||
|
||||
eZ Components team
|
||||
------------------
|
||||
|
||||
- Sergey Alexeev
|
||||
- Sebastian Bergmann
|
||||
- Jan Borsodi
|
||||
- Raymond Bosman
|
||||
- Frederik Holljen
|
||||
- Kore Nordmann
|
||||
- Derick Rethans
|
||||
- Vadym Savchuk
|
||||
- Tobias Schlitt
|
||||
- Alexandru Stanoi
|
||||
@@ -0,0 +1,113 @@
|
||||
1.1.3 - Monday 05 May 2008
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- Fixed bug #12638: ezcImageAnalyzerImagemagickHandler::checkImagemagick
|
||||
method missing SunOS in switch.
|
||||
|
||||
|
||||
1.1.2 - Monday 02 July 2007
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- Documentation updates and fixes.
|
||||
|
||||
|
||||
1.1.1 - Monday 25 June 2007
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- Documentation updates and fixes.
|
||||
|
||||
|
||||
1.1 - Monday 18 December 2006
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- Fixed issue #9493: Convert < and > in exception messages to ' and ' for
|
||||
Cache, ConsoleTools, ImageAnalysis, ImageConversion, PersistentObject,
|
||||
PersistentObjectDatabaseSchemaTiein.
|
||||
- Fixed issue #9819: Let all components deal with the ezcBaseAutoloadException
|
||||
properly.
|
||||
|
||||
|
||||
1.1beta1 - Monday 20 November 2006
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- Fixed issue #9013: SVG not detected in
|
||||
ezcImageImagemagickBaseHandler::determineTypes().
|
||||
|
||||
|
||||
1.0.1 - Monday 27 February 2006
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- Fixed unreported bug: ezcImageAnalyzerImagemagickHandler threw old exception
|
||||
style in isAvailable() if the operating system is not supported.
|
||||
|
||||
|
||||
1.0 - Monday 30 January 2006
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- Fixed bug #7606: Fatal error without exif-extension. Exif information is
|
||||
only provided when extension is available.
|
||||
|
||||
|
||||
1.0rc1 - Monday 16 January 2006
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- Added ezcImageAnalyzerHandler class (abstract base class for all handlers).
|
||||
- Added ezcImageAnalyzerPhpHandler (implementation of the original
|
||||
ImageAnalysis functionality in this handler).
|
||||
- Added ezcImageAnalyzerImagemagickHandler (still to implement, will use
|
||||
ImageMagick's "identify" binary to analyze a file).
|
||||
- Implemented automatic choosing and loading of a feasible handler in
|
||||
ezcImageAnalyzer.
|
||||
- Added static getHandlerClasses() and setHandlerClasses() methods on
|
||||
ezcImageAnalyzer to manipulate the handler classes.
|
||||
- Added ezcImageAnalyzerData struct to store the data gathered by an
|
||||
ezcImageAnalyzerHandler class.
|
||||
|
||||
- Changed exception behavior. All errors will now throw a different exception
|
||||
class.
|
||||
- Changed ImageAnalysis to be able to use multiple handlers (to be capable of
|
||||
analyzing more formats).
|
||||
- Changed ezcImageAnalyzer so that the data provided it provides is now
|
||||
accessed through $analyzer->data->value instead of $analyzer->value.
|
||||
|
||||
|
||||
1.0beta2 - Friday 23 December 2005
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
ezcImageAnalyzer
|
||||
================
|
||||
|
||||
- Changed class so that all information is available through overloaded
|
||||
properties.
|
||||
- Changed analyzeGeneric() to use getimagesize() which does not rely on any
|
||||
PHP extensions.
|
||||
- Changed the GIF scanning code to the one currently used in eZ publish 3.x,
|
||||
this scans each GIF block properly and looks for interesting information.
|
||||
The GIF analyzer will now in addition set the properties:
|
||||
|
||||
* width
|
||||
* height
|
||||
* mode
|
||||
* transparencyType
|
||||
* comment
|
||||
* commentList
|
||||
* colorCount
|
||||
|
||||
- Changed method names:
|
||||
|
||||
* processBasics() to analyzeType().
|
||||
* processExif() to analyzeExif().
|
||||
|
||||
- Added hasThumbnail property which reports whether the image has thumbnails
|
||||
available.
|
||||
|
||||
- Removed the methods getData(), getExtra(), getMime(). This data can now be
|
||||
accessed through properties instead.
|
||||
|
||||
- Fixed property list for GIFs, and made sure 'size' is set.
|
||||
|
||||
|
||||
1.0beta1 - Thursday 24 November 2005
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- Initial release of this package.
|
||||
@@ -0,0 +1,3 @@
|
||||
This class allows you to analyse image files in different ways. At least the
|
||||
MIME type of the file is returned. In some cases (JPEG, TIFF and GIF)
|
||||
additional information is gathered as well.
|
||||
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
@@ -0,0 +1,379 @@
|
||||
<?xml version="1.0" encoding="windows-1252"?>
|
||||
<XMI xmi.version="1.1" xmlns:UML="omg.org/UML1.3" timestamp="2005-08-19 13:15:59">
|
||||
<XMI.header>
|
||||
<XMI.documentation>
|
||||
<XMI.exporter>Enterprise Architect</XMI.exporter>
|
||||
<XMI.exporterVersion>2.5</XMI.exporterVersion>
|
||||
</XMI.documentation>
|
||||
</XMI.header>
|
||||
<XMI.content>
|
||||
<UML:Model name="EA Model" xmi.id="MX_EAID_E3373F4A_E4C2_451e_AE9D_FA23BB2D38FB">
|
||||
<UML:Namespace.ownedElement>
|
||||
<UML:Class name="EARootClass" xmi.id="EAID_11111111_5487_4080_A7F4_41526CB0AA00" isRoot="true" isLeaf="false" isAbstract="false"/>
|
||||
<UML:Package name="ImageAnalysis" xmi.id="EAPK_E3373F4A_E4C2_451e_AE9D_FA23BB2D38FB" isRoot="false" isLeaf="false" isAbstract="false" visibility="public">
|
||||
<UML:ModelElement.stereotype>
|
||||
<UML:Stereotype xmi.idref="EAID_C73DA4C3_382B_4956_A21C_88602C4F251D"/>
|
||||
</UML:ModelElement.stereotype>
|
||||
<UML:ModelElement.taggedValue>
|
||||
<UML:TaggedValue tag="documentation" value="Provides functionality for analyzing image formats and return detailed information about them, such as getting the EXIF information from a JPEG and TIFF or animation information from a GIF."/>
|
||||
<UML:TaggedValue tag="created" value="2005-08-11 00:00:00"/>
|
||||
<UML:TaggedValue tag="modified" value="2005-08-11 00:00:00"/>
|
||||
<UML:TaggedValue tag="iscontrolled" value="TRUE"/>
|
||||
<UML:TaggedValue tag="xmlpath" value="E:\src\ezcomponents\packages\ImageAnalysis\trunk\design\imageanalysis.xml"/>
|
||||
<UML:TaggedValue tag="lastsavedate" value="2005-08-19 13:15:59"/>
|
||||
<UML:TaggedValue tag="version" value="1.0"/>
|
||||
<UML:TaggedValue tag="isprotected" value="FALSE"/>
|
||||
<UML:TaggedValue tag="usedtd" value="FALSE"/>
|
||||
<UML:TaggedValue tag="owner" value="Jan Borsodi"/>
|
||||
<UML:TaggedValue tag="xmiver" value="Enterprise Architect XMI/UML 1.3"/>
|
||||
<UML:TaggedValue tag="logxml" value="FALSE"/>
|
||||
<UML:TaggedValue tag="codepath" value="E:\src\ezcomponents\ImageAnalysis"/>
|
||||
<UML:TaggedValue tag="packageFlags" value="CRC=0;"/>
|
||||
<UML:TaggedValue tag="batchsave" value="0"/>
|
||||
<UML:TaggedValue tag="batchload" value="0"/>
|
||||
<UML:TaggedValue tag="phase" value="1.0"/>
|
||||
<UML:TaggedValue tag="status" value="Proposed"/>
|
||||
<UML:TaggedValue tag="author" value="Tobias Schlitt"/>
|
||||
<UML:TaggedValue tag="complexity" value="1"/>
|
||||
<UML:TaggedValue tag="stereotype" value="ezcomponent"/>
|
||||
<UML:TaggedValue tag="ea_stype" value="Public"/>
|
||||
<UML:TaggedValue tag="tpos" value="0"/>
|
||||
</UML:ModelElement.taggedValue>
|
||||
<UML:Namespace.ownedElement>
|
||||
<UML:Class name="ezcImageAnalyzer" xmi.id="EAID_E2F60CEA_AAAF_4c70_891A_DFFE84C86811" visibility="public" namespace="EAPK_E3373F4A_E4C2_451e_AE9D_FA23BB2D38FB" isRoot="false" isLeaf="false" isAbstract="false" isActive="false">
|
||||
<UML:ModelElement.taggedValue>
|
||||
<UML:TaggedValue tag="documentation" value="Class to retreive information about a given image file. This class provides a simple static method to analyse image files in different ways. At least the MIME type of the file is returned. In some cases (by now JPEG, TIFF and GIF) additional information is included.
|
||||
<code> $analyzer = ezcImageAnalyzer('/var/cache/images/toby.jpg'); $mime = $analyzer->getMime(); if ($mime == 'image/tiff' || $mime == 'image/tiff') { $data = $analyzer->getExtra(); echo 'Photo taken on '.date('Y/m/d, H:i', $data['date']).".\n"; } else { echo "Unknowen photo format.\n"; }
|
||||
</code>
|
||||
@package ImageAnalysis
|
||||
@link http://www.gnu.org/copyleft/lesser.html}"/>
|
||||
<UML:TaggedValue tag="isSpecification" value="false"/>
|
||||
<UML:TaggedValue tag="ea_stype" value="Class"/>
|
||||
<UML:TaggedValue tag="ea_ntype" value="0"/>
|
||||
<UML:TaggedValue tag="version" value="//autogen//
|
||||
@copyright Copyright (C) 2005 eZ syst"/>
|
||||
<UML:TaggedValue tag="package" value="EAPK_E3373F4A_E4C2_451e_AE9D_FA23BB2D38FB"/>
|
||||
<UML:TaggedValue tag="date_created" value="2005-08-11 08:48:12"/>
|
||||
<UML:TaggedValue tag="date_modified" value="2005-08-19 13:15:34"/>
|
||||
<UML:TaggedValue tag="genfile" value="E:\src\ezcomponents\packages\ImageAnalysis\trunk\src\image\analyzer.php"/>
|
||||
<UML:TaggedValue tag="gentype" value="PHP"/>
|
||||
<UML:TaggedValue tag="tagged" value="0"/>
|
||||
<UML:TaggedValue tag="package_name" value="ImageAnalysis"/>
|
||||
<UML:TaggedValue tag="phase" value="1.0"/>
|
||||
<UML:TaggedValue tag="author" value="Jan Borsodi"/>
|
||||
<UML:TaggedValue tag="complexity" value="1"/>
|
||||
<UML:TaggedValue tag="status" value="Proposed"/>
|
||||
<UML:TaggedValue tag="style" value="BackColor=-1;BorderColor=-1;BorderWidth=-1;FontColor=-1;VSwimLanes=0;HSwimLanes=0;BorderStyle=0;"/>
|
||||
</UML:ModelElement.taggedValue>
|
||||
<UML:Classifier.feature>
|
||||
<UML:Operation name="__construct" visibility="public" ownerScope="instance" isQuery="false" concurrency="sequential">
|
||||
<UML:ModelElement.taggedValue>
|
||||
<UML:TaggedValue tag="documentation" value="Create an image analyzer. Create an ezcImageAnalyzer. Use methods to gather information.
|
||||
@param string The file to analyse. "/>
|
||||
<UML:TaggedValue tag="type" value="var"/>
|
||||
<UML:TaggedValue tag="const" value="false"/>
|
||||
<UML:TaggedValue tag="synchronised" value="0"/>
|
||||
<UML:TaggedValue tag="concurrency" value="Sequential"/>
|
||||
<UML:TaggedValue tag="position" value="0"/>
|
||||
<UML:TaggedValue tag="returnarray" value="0"/>
|
||||
<UML:TaggedValue tag="pure" value="0"/>
|
||||
<UML:TaggedValue tag="ea_guid" value="{0007F774-8293-4759-85C0-24EB705930A0}"/>
|
||||
</UML:ModelElement.taggedValue>
|
||||
<UML:BehavioralFeature.parameter>
|
||||
<UML:Parameter kind="return" visibility="public">
|
||||
<UML:Parameter.type>
|
||||
<UML:Classifier xmi.idref="eaxmiid0"/>
|
||||
</UML:Parameter.type>
|
||||
<UML:ModelElement.taggedValue>
|
||||
<UML:TaggedValue tag="pos" value="0"/>
|
||||
<UML:TaggedValue tag="type" value="var"/>
|
||||
<UML:TaggedValue tag="const" value="0"/>
|
||||
<UML:TaggedValue tag="ea_guid" value="{RETURNID-8293-4759-85C0-24EB705930A0}"/>
|
||||
</UML:ModelElement.taggedValue>
|
||||
<UML:Parameter.defaultValue>
|
||||
<UML:Expression/>
|
||||
</UML:Parameter.defaultValue>
|
||||
</UML:Parameter>
|
||||
<UML:Parameter name="file" kind="in" visibility="public">
|
||||
<UML:Parameter.type>
|
||||
<UML:Classifier xmi.idref="eaxmiid0"/>
|
||||
</UML:Parameter.type>
|
||||
<UML:ModelElement.taggedValue>
|
||||
<UML:TaggedValue tag="pos" value="0"/>
|
||||
<UML:TaggedValue tag="type" value="var"/>
|
||||
<UML:TaggedValue tag="const" value="0"/>
|
||||
<UML:TaggedValue tag="ea_guid" value="{47896A28-B3A4-49eb-94E8-89D030175EA9}"/>
|
||||
</UML:ModelElement.taggedValue>
|
||||
<UML:Parameter.defaultValue>
|
||||
<UML:Expression/>
|
||||
</UML:Parameter.defaultValue>
|
||||
</UML:Parameter>
|
||||
</UML:BehavioralFeature.parameter>
|
||||
</UML:Operation>
|
||||
<UML:Operation name="getData" visibility="public" ownerScope="instance" isQuery="false" concurrency="sequential">
|
||||
<UML:ModelElement.taggedValue>
|
||||
<UML:TaggedValue tag="documentation" value="Return all collected data from analyzation.
|
||||
<code> array( 'mime' => '<mimeType>', 'extra' => array(), // optional extra information, depends on MIME type if set. 'raw' => array(), );
|
||||
</code>
|
||||
@return array All collected data."/>
|
||||
<UML:TaggedValue tag="type" value="var"/>
|
||||
<UML:TaggedValue tag="const" value="false"/>
|
||||
<UML:TaggedValue tag="synchronised" value="0"/>
|
||||
<UML:TaggedValue tag="concurrency" value="Sequential"/>
|
||||
<UML:TaggedValue tag="position" value="1"/>
|
||||
<UML:TaggedValue tag="returnarray" value="0"/>
|
||||
<UML:TaggedValue tag="pure" value="0"/>
|
||||
<UML:TaggedValue tag="ea_guid" value="{7A96A448-BA6C-4083-8C98-403A99F15E3A}"/>
|
||||
</UML:ModelElement.taggedValue>
|
||||
<UML:BehavioralFeature.parameter>
|
||||
<UML:Parameter kind="return" visibility="public">
|
||||
<UML:Parameter.type>
|
||||
<UML:Classifier xmi.idref="eaxmiid0"/>
|
||||
</UML:Parameter.type>
|
||||
<UML:ModelElement.taggedValue>
|
||||
<UML:TaggedValue tag="pos" value="0"/>
|
||||
<UML:TaggedValue tag="type" value="var"/>
|
||||
<UML:TaggedValue tag="const" value="0"/>
|
||||
<UML:TaggedValue tag="ea_guid" value="{RETURNID-BA6C-4083-8C98-403A99F15E3A}"/>
|
||||
</UML:ModelElement.taggedValue>
|
||||
<UML:Parameter.defaultValue>
|
||||
<UML:Expression/>
|
||||
</UML:Parameter.defaultValue>
|
||||
</UML:Parameter>
|
||||
</UML:BehavioralFeature.parameter>
|
||||
</UML:Operation>
|
||||
<UML:Operation name="getMime" visibility="public" ownerScope="instance" isQuery="false" concurrency="sequential">
|
||||
<UML:ModelElement.taggedValue>
|
||||
<UML:TaggedValue tag="documentation" value="Return MIME type of the file. Returned MIME type is completly lowercase like "image/jpeg".
|
||||
@return string MIME type."/>
|
||||
<UML:TaggedValue tag="type" value="var"/>
|
||||
<UML:TaggedValue tag="const" value="false"/>
|
||||
<UML:TaggedValue tag="synchronised" value="0"/>
|
||||
<UML:TaggedValue tag="concurrency" value="Sequential"/>
|
||||
<UML:TaggedValue tag="position" value="2"/>
|
||||
<UML:TaggedValue tag="returnarray" value="0"/>
|
||||
<UML:TaggedValue tag="pure" value="0"/>
|
||||
<UML:TaggedValue tag="ea_guid" value="{1AEE41B8-52D6-4106-A701-F45277C7B167}"/>
|
||||
</UML:ModelElement.taggedValue>
|
||||
<UML:BehavioralFeature.parameter>
|
||||
<UML:Parameter kind="return" visibility="public">
|
||||
<UML:Parameter.type>
|
||||
<UML:Classifier xmi.idref="eaxmiid0"/>
|
||||
</UML:Parameter.type>
|
||||
<UML:ModelElement.taggedValue>
|
||||
<UML:TaggedValue tag="pos" value="0"/>
|
||||
<UML:TaggedValue tag="type" value="var"/>
|
||||
<UML:TaggedValue tag="const" value="0"/>
|
||||
<UML:TaggedValue tag="ea_guid" value="{RETURNID-52D6-4106-A701-F45277C7B167}"/>
|
||||
</UML:ModelElement.taggedValue>
|
||||
<UML:Parameter.defaultValue>
|
||||
<UML:Expression/>
|
||||
</UML:Parameter.defaultValue>
|
||||
</UML:Parameter>
|
||||
</UML:BehavioralFeature.parameter>
|
||||
</UML:Operation>
|
||||
<UML:Operation name="getExtra" visibility="public" ownerScope="instance" isQuery="false" concurrency="sequential">
|
||||
<UML:ModelElement.taggedValue>
|
||||
<UML:TaggedValue tag="documentation" value="Returns extra information on the file. Works only with specific file types and is a cleaned up version of EXIF data (for JPEG/TIFF) or other available analyzeable data. The data array may contain:
|
||||
<code> array( 'width' => <int>, // Width in px 'height' => <int>, // Height in px 'size' => <int>, // Filesize in byte 'iscolor' => <bool>, // Color image? 'comment' => <string>, // Comment contained in picture 'copyright' => <string>, // Embeded copyright 'date' => <int>, // Photo taken date (Unix time) ... 'animated' => <bool>, // True for animated GIFs );
|
||||
</code>
|
||||
@return array"/>
|
||||
<UML:TaggedValue tag="type" value="var"/>
|
||||
<UML:TaggedValue tag="const" value="false"/>
|
||||
<UML:TaggedValue tag="synchronised" value="0"/>
|
||||
<UML:TaggedValue tag="concurrency" value="Sequential"/>
|
||||
<UML:TaggedValue tag="position" value="3"/>
|
||||
<UML:TaggedValue tag="returnarray" value="0"/>
|
||||
<UML:TaggedValue tag="pure" value="0"/>
|
||||
<UML:TaggedValue tag="ea_guid" value="{F8B7ED10-6CEC-4634-8214-C71AE4224429}"/>
|
||||
</UML:ModelElement.taggedValue>
|
||||
<UML:BehavioralFeature.parameter>
|
||||
<UML:Parameter kind="return" visibility="public">
|
||||
<UML:Parameter.type>
|
||||
<UML:Classifier xmi.idref="eaxmiid0"/>
|
||||
</UML:Parameter.type>
|
||||
<UML:ModelElement.taggedValue>
|
||||
<UML:TaggedValue tag="pos" value="0"/>
|
||||
<UML:TaggedValue tag="type" value="var"/>
|
||||
<UML:TaggedValue tag="const" value="0"/>
|
||||
<UML:TaggedValue tag="ea_guid" value="{RETURNID-6CEC-4634-8214-C71AE4224429}"/>
|
||||
</UML:ModelElement.taggedValue>
|
||||
<UML:Parameter.defaultValue>
|
||||
<UML:Expression/>
|
||||
</UML:Parameter.defaultValue>
|
||||
</UML:Parameter>
|
||||
</UML:BehavioralFeature.parameter>
|
||||
</UML:Operation>
|
||||
<UML:Operation name="getRaw" visibility="public" ownerScope="instance" isQuery="false" concurrency="sequential">
|
||||
<UML:ModelElement.taggedValue>
|
||||
<UML:TaggedValue tag="documentation" value="Returns RAW collected data. Returns an array of the RAW collected data. For JPEG and TIFF this is the EXIF array. For GIF, just an array containing the 'animated' key.
|
||||
@link http://php.net/manual/en/function.exif-read-data.php
|
||||
@returns array()"/>
|
||||
<UML:TaggedValue tag="type" value="var"/>
|
||||
<UML:TaggedValue tag="const" value="false"/>
|
||||
<UML:TaggedValue tag="synchronised" value="0"/>
|
||||
<UML:TaggedValue tag="concurrency" value="Sequential"/>
|
||||
<UML:TaggedValue tag="position" value="4"/>
|
||||
<UML:TaggedValue tag="returnarray" value="0"/>
|
||||
<UML:TaggedValue tag="pure" value="0"/>
|
||||
<UML:TaggedValue tag="ea_guid" value="{EB9D5FD9-180B-43ee-AAE0-43BC14B6CCDE}"/>
|
||||
</UML:ModelElement.taggedValue>
|
||||
<UML:BehavioralFeature.parameter>
|
||||
<UML:Parameter kind="return" visibility="public">
|
||||
<UML:Parameter.type>
|
||||
<UML:Classifier xmi.idref="eaxmiid0"/>
|
||||
</UML:Parameter.type>
|
||||
<UML:ModelElement.taggedValue>
|
||||
<UML:TaggedValue tag="pos" value="0"/>
|
||||
<UML:TaggedValue tag="type" value="var"/>
|
||||
<UML:TaggedValue tag="const" value="0"/>
|
||||
<UML:TaggedValue tag="ea_guid" value="{RETURNID-180B-43ee-AAE0-43BC14B6CCDE}"/>
|
||||
</UML:ModelElement.taggedValue>
|
||||
<UML:Parameter.defaultValue>
|
||||
<UML:Expression/>
|
||||
</UML:Parameter.defaultValue>
|
||||
</UML:Parameter>
|
||||
</UML:BehavioralFeature.parameter>
|
||||
</UML:Operation>
|
||||
<UML:Operation name="processExif" visibility="private" ownerScope="instance" isQuery="false" concurrency="sequential">
|
||||
<UML:ModelElement.taggedValue>
|
||||
<UML:TaggedValue tag="documentation" value="Analyses files containing EXIF information. Analyses JPEG and TIFF images.
|
||||
@param string The file to process.
|
||||
@return array(string) Information gathered from EXIF."/>
|
||||
<UML:TaggedValue tag="type" value="var"/>
|
||||
<UML:TaggedValue tag="const" value="false"/>
|
||||
<UML:TaggedValue tag="static" value="1"/>
|
||||
<UML:TaggedValue tag="synchronised" value="0"/>
|
||||
<UML:TaggedValue tag="concurrency" value="Sequential"/>
|
||||
<UML:TaggedValue tag="position" value="5"/>
|
||||
<UML:TaggedValue tag="returnarray" value="0"/>
|
||||
<UML:TaggedValue tag="pure" value="0"/>
|
||||
<UML:TaggedValue tag="ea_guid" value="{641BBA26-251E-4454-B745-22294CCB798A}"/>
|
||||
</UML:ModelElement.taggedValue>
|
||||
<UML:BehavioralFeature.parameter>
|
||||
<UML:Parameter kind="return" visibility="public">
|
||||
<UML:Parameter.type>
|
||||
<UML:Classifier xmi.idref="eaxmiid0"/>
|
||||
</UML:Parameter.type>
|
||||
<UML:ModelElement.taggedValue>
|
||||
<UML:TaggedValue tag="pos" value="0"/>
|
||||
<UML:TaggedValue tag="type" value="var"/>
|
||||
<UML:TaggedValue tag="const" value="0"/>
|
||||
<UML:TaggedValue tag="ea_guid" value="{RETURNID-251E-4454-B745-22294CCB798A}"/>
|
||||
</UML:ModelElement.taggedValue>
|
||||
<UML:Parameter.defaultValue>
|
||||
<UML:Expression/>
|
||||
</UML:Parameter.defaultValue>
|
||||
</UML:Parameter>
|
||||
<UML:Parameter name="file" kind="in" visibility="public">
|
||||
<UML:Parameter.type>
|
||||
<UML:Classifier xmi.idref="eaxmiid0"/>
|
||||
</UML:Parameter.type>
|
||||
<UML:ModelElement.taggedValue>
|
||||
<UML:TaggedValue tag="pos" value="0"/>
|
||||
<UML:TaggedValue tag="type" value="var"/>
|
||||
<UML:TaggedValue tag="const" value="0"/>
|
||||
<UML:TaggedValue tag="ea_guid" value="{A755592F-C7EC-42a8-AA8E-01C147B049B7}"/>
|
||||
</UML:ModelElement.taggedValue>
|
||||
<UML:Parameter.defaultValue>
|
||||
<UML:Expression/>
|
||||
</UML:Parameter.defaultValue>
|
||||
</UML:Parameter>
|
||||
</UML:BehavioralFeature.parameter>
|
||||
</UML:Operation>
|
||||
<UML:Operation name="processGif" visibility="private" ownerScope="instance" isQuery="false" concurrency="sequential">
|
||||
<UML:ModelElement.taggedValue>
|
||||
<UML:TaggedValue tag="documentation" value="Analyse GIF files. Analyse GIF files and check if they are animated.
|
||||
@param string The file to process
|
||||
@return array(string) Information gathered from the file."/>
|
||||
<UML:TaggedValue tag="type" value="var"/>
|
||||
<UML:TaggedValue tag="const" value="false"/>
|
||||
<UML:TaggedValue tag="static" value="1"/>
|
||||
<UML:TaggedValue tag="synchronised" value="0"/>
|
||||
<UML:TaggedValue tag="concurrency" value="Sequential"/>
|
||||
<UML:TaggedValue tag="position" value="6"/>
|
||||
<UML:TaggedValue tag="returnarray" value="0"/>
|
||||
<UML:TaggedValue tag="pure" value="0"/>
|
||||
<UML:TaggedValue tag="ea_guid" value="{83060E96-2D4F-40a0-8B45-96909334B7D4}"/>
|
||||
</UML:ModelElement.taggedValue>
|
||||
<UML:BehavioralFeature.parameter>
|
||||
<UML:Parameter kind="return" visibility="public">
|
||||
<UML:Parameter.type>
|
||||
<UML:Classifier xmi.idref="eaxmiid0"/>
|
||||
</UML:Parameter.type>
|
||||
<UML:ModelElement.taggedValue>
|
||||
<UML:TaggedValue tag="pos" value="0"/>
|
||||
<UML:TaggedValue tag="type" value="var"/>
|
||||
<UML:TaggedValue tag="const" value="0"/>
|
||||
<UML:TaggedValue tag="ea_guid" value="{RETURNID-2D4F-40a0-8B45-96909334B7D4}"/>
|
||||
</UML:ModelElement.taggedValue>
|
||||
<UML:Parameter.defaultValue>
|
||||
<UML:Expression/>
|
||||
</UML:Parameter.defaultValue>
|
||||
</UML:Parameter>
|
||||
<UML:Parameter name="file" kind="in" visibility="public">
|
||||
<UML:Parameter.type>
|
||||
<UML:Classifier xmi.idref="eaxmiid0"/>
|
||||
</UML:Parameter.type>
|
||||
<UML:ModelElement.taggedValue>
|
||||
<UML:TaggedValue tag="pos" value="0"/>
|
||||
<UML:TaggedValue tag="type" value="var"/>
|
||||
<UML:TaggedValue tag="const" value="0"/>
|
||||
<UML:TaggedValue tag="ea_guid" value="{97FCC7FE-06A1-4da2-BE98-777A09BB2644}"/>
|
||||
</UML:ModelElement.taggedValue>
|
||||
<UML:Parameter.defaultValue>
|
||||
<UML:Expression/>
|
||||
</UML:Parameter.defaultValue>
|
||||
</UML:Parameter>
|
||||
</UML:BehavioralFeature.parameter>
|
||||
</UML:Operation>
|
||||
</UML:Classifier.feature>
|
||||
</UML:Class>
|
||||
<UML:Comment xmi.id="EAID_E4744CDF_921F_45eb_BF75_0B329C01C49C" visibility="public" namespace="EAPK_E3373F4A_E4C2_451e_AE9D_FA23BB2D38FB">
|
||||
<UML:ModelElement.taggedValue>
|
||||
<UML:TaggedValue tag="isSpecification" value="false"/>
|
||||
<UML:TaggedValue tag="ea_stype" value="Text"/>
|
||||
<UML:TaggedValue tag="ea_ntype" value="18"/>
|
||||
<UML:TaggedValue tag="version" value="1.0"/>
|
||||
<UML:TaggedValue tag="package" value="EAPK_E3373F4A_E4C2_451e_AE9D_FA23BB2D38FB"/>
|
||||
<UML:TaggedValue tag="date_created" value="2005-08-11 08:49:04"/>
|
||||
<UML:TaggedValue tag="date_modified" value="2005-08-11 08:49:04"/>
|
||||
<UML:TaggedValue tag="gentype" value="<none>"/>
|
||||
<UML:TaggedValue tag="tagged" value="0"/>
|
||||
<UML:TaggedValue tag="package_name" value="ImageAnalysis"/>
|
||||
<UML:TaggedValue tag="phase" value="1.0"/>
|
||||
<UML:TaggedValue tag="author" value="Jan Borsodi"/>
|
||||
<UML:TaggedValue tag="complexity" value="1"/>
|
||||
<UML:TaggedValue tag="status" value="Proposed"/>
|
||||
<UML:TaggedValue tag="style" value="BackColor=-1;BorderColor=-1;BorderWidth=-1;FontColor=-1;VSwimLanes=0;HSwimLanes=0;BorderStyle=0;"/>
|
||||
</UML:ModelElement.taggedValue>
|
||||
</UML:Comment>
|
||||
</UML:Namespace.ownedElement>
|
||||
</UML:Package>
|
||||
<UML:Stereotype xmi.id="EAID_C73DA4C3_382B_4956_A21C_88602C4F251D" name="ezcomponent" isRoot="false" isLeaf="false" isAbstract="false">
|
||||
<UML:Stereotype.baseClass>Package</UML:Stereotype.baseClass>
|
||||
</UML:Stereotype>
|
||||
<UML:DataType xmi.id="eaxmiid0" name="var" visibility="private" isRoot="false" isLeaf="false" isAbstract="false"/>
|
||||
</UML:Namespace.ownedElement>
|
||||
</UML:Model>
|
||||
<UML:Diagram name="Image analyzer" xmi.id="EAID_D0B606F1_42CA_4cbd_A0F7_19E8C9FA6B60" diagramType="ClassDiagram" owner="EAPK_E3373F4A_E4C2_451e_AE9D_FA23BB2D38FB" toolName="Enterprise Architect 2.5">
|
||||
<UML:ModelElement.taggedValue>
|
||||
<UML:TaggedValue tag="version" value="0.1"/>
|
||||
<UML:TaggedValue tag="author" value="Tobias Schlitt"/>
|
||||
<UML:TaggedValue tag="created_date" value="2005-08-11 08:48:12"/>
|
||||
<UML:TaggedValue tag="modified_date" value="2005-08-19 13:15:44"/>
|
||||
<UML:TaggedValue tag="package" value="EAPK_E3373F4A_E4C2_451e_AE9D_FA23BB2D38FB"/>
|
||||
<UML:TaggedValue tag="type" value="Logical"/>
|
||||
<UML:TaggedValue tag="swimlanes" value="locked=false;orientation=0;width=0;inbar=false;names=false;color=0;bold=false;fcol=0;;cls=0;"/>
|
||||
<UML:TaggedValue tag="EAStyle" value="ShowPrivate=1;ShowProtected=1;ShowPublic=1;HideRelationships=0;Locked=0;Border=1;HighlightForeign=1;PackageContents=1;SequenceNotes=0;ScalePrintImage=0;PPgs.cx=0;PPgs.cy=0;DocSize.cx=780;DocSize.cy=1118;ShowDetails=0;Orientation=P;Zoom=100;ShowTags=0;OpParams=3;ShowIcons=1;CollabNums=0;HideProps=0;ShowReqs=0;ShowCons=0;PaperSize=9;HideParents=0;UseAlias=0;HideAtts=0;HideOps=0;HideStereo=0;HideElemStereo=0;ShowTests=0;ShowMaint=0;"/>
|
||||
<UML:TaggedValue tag="styleex" value="ExcludeRTF=0;DocAll=0;HideQuals=0;AttPkg=1;ShowTests=0;ShowMaint=0;Layout=l=20:c=20:d=0:cr=1:la=2:i=1:it=4:a=0:;SuppressFOC=0;TDurLow=0;TDurHigh=100;TDurUnit=;TDurHide=0;"/>
|
||||
</UML:ModelElement.taggedValue>
|
||||
<UML:Diagram.element>
|
||||
<UML:DiagramElement geometry="Left=20;Top=20;Right=185;Bottom=95;" subject="EAID_E4744CDF_921F_45eb_BF75_0B329C01C49C" seqno="1" style="DUID=9280C022;"/>
|
||||
<UML:DiagramElement geometry="Left=215;Top=20;Right=339;Bottom=151;" subject="EAID_E2F60CEA_AAAF_4c70_891A_DFFE84C86811" seqno="2" style="DUID=A8014A4D;LBL=;"/>
|
||||
</UML:Diagram.element>
|
||||
</UML:Diagram>
|
||||
</XMI.content>
|
||||
<XMI.difference/>
|
||||
<XMI.extensions xmi.extender="Enterprise Architect 2.5"/>
|
||||
</XMI>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
require_once 'Base/src/base.php';
|
||||
|
||||
/**
|
||||
* Autoload ezc classes
|
||||
*
|
||||
* @param string $className
|
||||
*/
|
||||
function __autoload( $className )
|
||||
{
|
||||
ezcBase::autoload( $className );
|
||||
}
|
||||
|
||||
// Analyzation of the MIME type is done during creation.
|
||||
$image = new ezcImageAnalyzer( dirname( __FILE__ ).'/toby.jpg' );
|
||||
|
||||
if ( $image->mime == 'image/tiff' || $image->mime == 'image/jpeg' )
|
||||
{
|
||||
// Analyzation of further image data is done during access of the data
|
||||
echo 'Photo taken on '.date( 'Y/m/d, H:i', $image->data->date ).".\n";
|
||||
}
|
||||
elseif ( $mime !== false )
|
||||
{
|
||||
echo "Format was detected as {$mime}.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Unknown photo format.\n";
|
||||
}
|
||||
|
||||
?>
|
||||
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 75 KiB |
@@ -0,0 +1,126 @@
|
||||
eZ Components - ImageAnalysis
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. contents:: Table of Contents
|
||||
|
||||
Introduction
|
||||
============
|
||||
|
||||
The ImageAnalysis component allows you to analyze certain image attributes.
|
||||
|
||||
Class overview
|
||||
==============
|
||||
|
||||
ezcImageAnalyzer is the main class for this component. It is responsible for
|
||||
handling the analysis of image files, as well as caching the results.
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
MIME type determination
|
||||
-----------------------
|
||||
|
||||
The following example simply detects the MIME type of an image and prints it:
|
||||
|
||||
.. include:: tutorial_example_01.php
|
||||
:literal:
|
||||
|
||||
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:: img/imageanalysis_example_01.jpg
|
||||
:alt: Simple JPEG image.
|
||||
|
||||
::
|
||||
|
||||
Image has MIME type <image/jpeg>
|
||||
|
||||
Extracting further data
|
||||
-----------------------
|
||||
|
||||
Aside from the MIME type, ImageAnalysis can extract other image information.
|
||||
The following example demonstrates this:
|
||||
|
||||
.. include:: tutorial_example_02.php
|
||||
:literal:
|
||||
|
||||
The example is basically the same as the first one, except that more data is requested
|
||||
from ezcImageAnalyzer (lines 8 to 11). The analysis of additional data
|
||||
begins on line 9. After that, the data is cached in the ezcImageAnalyzer object.
|
||||
|
||||
The width, height and size values are available for every analyzable image.
|
||||
A comment is not always available. If an image property is not available, the
|
||||
output will be some sensible default value (such as n/a). (Note that the
|
||||
availability of some data also depends on the availability of PHP's Exif
|
||||
extension.)
|
||||
|
||||
The example image and printed output is shown below:
|
||||
|
||||
.. image:: img/imageanalysis_example_02.jpg
|
||||
|
||||
::
|
||||
|
||||
Image data:
|
||||
MIME type: image/jpeg
|
||||
Width: 380 px
|
||||
Height: 285 px
|
||||
Filesize: 25984 b
|
||||
Comment: n/a
|
||||
|
||||
|
||||
Configuring handlers
|
||||
--------------------
|
||||
|
||||
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:
|
||||
|
||||
.. _ImageMagick: http://www.imagemagick.org/script/index.php
|
||||
|
||||
.. include:: tutorial_example_03.php
|
||||
:literal:
|
||||
|
||||
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:: img/imageanalysis_example_03.jpg
|
||||
|
||||
::
|
||||
|
||||
Image data:
|
||||
MIME type: image/jpeg
|
||||
Width: 320 px
|
||||
Height: 240 px
|
||||
Filesize: 26365 b
|
||||
Comment: San Francisco airport, October 2005.
|
||||
|
||||
More information
|
||||
================
|
||||
|
||||
For more information, see the ezcImageAnalyzer API documentation.
|
||||
|
||||
|
||||
..
|
||||
Local Variables:
|
||||
mode: rst
|
||||
fill-column: 79
|
||||
End:
|
||||
vim: et syn=rst tw=79
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
$dir = dirname( __FILE__ );
|
||||
$dirParts = explode( '/', $dir );
|
||||
switch ( $dirParts[count( $dirParts ) - 3] )
|
||||
{
|
||||
case 'doc': require_once 'ezc/Base/base.php'; break; // pear
|
||||
case 'trunk': require_once "$dir/../../Base/src/base.php"; break; // svn
|
||||
default: require_once "$dir/../../Base/src/base.php"; break; // bundle
|
||||
}
|
||||
|
||||
/**
|
||||
* Autoload ezc classes
|
||||
*
|
||||
* @param string $className
|
||||
*/
|
||||
function __autoload( $className )
|
||||
{
|
||||
ezcBase::autoload( $className );
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?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";
|
||||
?>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
require_once 'tutorial_autoload.php';
|
||||
$tutorialPath = dirname( __FILE__ );
|
||||
|
||||
$image = new ezcImageAnalyzer( $tutorialPath.'/img/imageanalysis_example_02.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";
|
||||
?>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?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";
|
||||
?>
|
||||
@@ -0,0 +1,354 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the ezcImageAnalyzer class.
|
||||
*
|
||||
* @package ImageAnalysis
|
||||
* @version 1.1.3
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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 {@link 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 {@link ezcImageAnalyzerFileNotProcessableException}.
|
||||
*
|
||||
* In this package the following handlers are available (in their priority
|
||||
* order):
|
||||
* - {@link ezcImageAnalyzerImagemagickHandler}, which uses the ImageMagick
|
||||
* binary "identify" to collect information about an image.
|
||||
* - {@link ezcImageAnalyzerPhpHandler}, which relies on the GD extension and
|
||||
* is capable of using the exif extension to determine additional data.
|
||||
*
|
||||
* For detailed information on the data provided by these handlers,
|
||||
* their capabilities on analyzing images and their speciallties, please
|
||||
* take a look at their documentation. For general information on handlers,
|
||||
* look at {@link ezcImageAnalyzerHandler},
|
||||
* {@link ezcImageAnalyzer::getHandlerClasses()} and
|
||||
* {@link ezcImageAnalyzer::setHandlerClasses()}.
|
||||
*
|
||||
* A simple example.
|
||||
* <code>
|
||||
* // Analyzation of the MIME type is done during creation.
|
||||
* $image = new ezcImageAnalyzer( dirname( __FILE__ ).'/toby.jpg' );
|
||||
*
|
||||
* if ( $image->mime == 'image/tiff' || $image->mime == 'image/jpeg' )
|
||||
* {
|
||||
* // Analyzation of further image data is done during access of the data
|
||||
* echo 'Photo taken on '.date( 'Y/m/d, H:i', $image->data->date ).".\n";
|
||||
* }
|
||||
* elseif ( $mime !== false )
|
||||
* {
|
||||
* echo "Format was detected as {$mime}.\n";
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* echo "Unknown photo format.\n";
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* If you want to manipulate the handlers used by ezcImageAnalyzer, you can do
|
||||
* this globally like this:
|
||||
* <code>
|
||||
* // Retreive the predefined handler classes
|
||||
* $originalHandlers = ezcImageAnalyzer::getHandlerClasses();
|
||||
* 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.
|
||||
* ezcImageAnalyzer::setHandlerClasses( $handlerClasses );
|
||||
*
|
||||
* // Somewhere else in the code... This now tries to use your handler in the
|
||||
* // first place
|
||||
* $image = new ezcImageAnalyzer( '/var/cache/images/toby.jpg' );
|
||||
* </code>
|
||||
*
|
||||
* Or you can define your own handler classes to be used (beware, those must
|
||||
* either be already loaded or load automatically on access).
|
||||
* <code>
|
||||
* // Define your onw handler class to be used in the first place and fall back on
|
||||
* // ImageMagick, if necessary.
|
||||
* $handlerClasses = array( 'MyOwnHandlerClass', 'ezcImageAnalyzerImagemagickHandler' );
|
||||
* ezcImageAnalyzer::setHandlerClasses( $handlerClasses );
|
||||
*
|
||||
* // Somewehre else in the code... This now tries to use your handler in the
|
||||
* // first place
|
||||
* $image = new ezcImageAnalyzer( '/var/cache/images/toby.jpg' );
|
||||
* </code>
|
||||
*
|
||||
* @property-read string $mime
|
||||
* The MIME type of the image.
|
||||
* @property-read ezcImageAnalyzerData $data
|
||||
* Extended data about the image.
|
||||
*
|
||||
* @package ImageAnalysis
|
||||
* @version 1.1.3
|
||||
*/
|
||||
class ezcImageAnalyzer
|
||||
{
|
||||
/**
|
||||
* The path of the file to analyze.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $filePath;
|
||||
|
||||
/**
|
||||
* Determines whether the image file has been analyzed or not.
|
||||
* This is used internally.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $isAnalyzed;
|
||||
|
||||
/**
|
||||
* Container to hold the properties
|
||||
*
|
||||
* @var array(string=>mixed)
|
||||
*/
|
||||
protected $properties;
|
||||
|
||||
/**
|
||||
* Collection of known handler classes. Classes are ordered by priority.
|
||||
*
|
||||
* @var array(string=>mixed)
|
||||
*/
|
||||
protected static $knownHandlers = array(
|
||||
'ezcImageAnalyzerPhpHandler' => array(),
|
||||
'ezcImageAnalyzerImagemagickHandler' => array(),
|
||||
);
|
||||
|
||||
/**
|
||||
* Available handler classes and their options.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $availableHandlers;
|
||||
|
||||
/**
|
||||
* Create an image analyzer for the specified file.
|
||||
*
|
||||
* @throws ezcBaseFilePermissionException
|
||||
* If image file is not readable.
|
||||
* @throws ezcBaseFileNotFoundException
|
||||
* If image file does not exist.
|
||||
* @throws ezcImageAnalyzerFileNotProcessableException
|
||||
* If the file could not be processed.
|
||||
* @param string $file The file to analyze.
|
||||
*/
|
||||
public function __construct( $file )
|
||||
{
|
||||
if ( !file_exists( $file ) || !is_file( $file ) )
|
||||
{
|
||||
throw new ezcBaseFileNotFoundException( $file );
|
||||
}
|
||||
if ( !is_readable( $file ) )
|
||||
{
|
||||
throw new ezcBaseFilePermissionException( $file, ezcBaseFileException::READ );
|
||||
}
|
||||
$this->filePath = $file;
|
||||
$this->isAnalyzed = false;
|
||||
|
||||
$this->checkHandlers();
|
||||
|
||||
$this->analyzeType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check all known handlers for availability.
|
||||
*
|
||||
* This method checks all registered handler classes for if the they are
|
||||
* available (using {@link ezcImageAnalyzerHandler::isAvailable()}).
|
||||
*
|
||||
* @throws ezcImageAnalyzerInvalidHandlerException
|
||||
* If a registered handler class does not exist
|
||||
* or does not inherit from {@link ezcImageAnalyzerHandler}.
|
||||
*/
|
||||
protected function checkHandlers()
|
||||
{
|
||||
if ( isset( ezcImageAnalyzer::$availableHandlers ) && is_array( ezcImageAnalyzer::$availableHandlers ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
ezcImageAnalyzer::$availableHandlers = array();
|
||||
foreach ( ezcImageAnalyzer::$knownHandlers as $handlerClass => $options )
|
||||
{
|
||||
if ( !ezcBaseFeatures::classExists( $handlerClass ) || !is_subclass_of( $handlerClass, 'ezcImageAnalyzerHandler' ) )
|
||||
{
|
||||
throw new ezcImageAnalyzerInvalidHandlerException( $handlerClass );
|
||||
}
|
||||
$handler = new $handlerClass( $options );
|
||||
if ( $handler->isAvailable() )
|
||||
{
|
||||
ezcImageAnalyzer::$availableHandlers[] = clone( $handler );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @return array(string=>array(string=>string)) Handlers and options.
|
||||
*/
|
||||
public static function getHandlerClasses()
|
||||
{
|
||||
return ezcImageAnalyzer::$knownHandlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param array(string=>array(string=>string)) $handlerClasses Handlers
|
||||
* and options.
|
||||
*/
|
||||
public static function setHandlerClasses( array $handlerClasses )
|
||||
{
|
||||
ezcImageAnalyzer::$knownHandlers = $handlerClasses;
|
||||
ezcImageAnalyzer::$availableHandlers = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property $name to $value.
|
||||
*
|
||||
* @throws ezcBasePropertyNotFoundException
|
||||
* If the property does not exist.
|
||||
* @throws ezcBasePropertyPermissionException
|
||||
* If the property cannot be modified.
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @ignore
|
||||
*/
|
||||
public function __set( $name, $value )
|
||||
{
|
||||
switch ( $name )
|
||||
{
|
||||
case 'mime':
|
||||
case 'data':
|
||||
throw new ezcBasePropertyPermissionException( $name, ezcBasePropertyPermissionException::READ );
|
||||
default:
|
||||
throw new ezcBasePropertyNotFoundException( $name );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the property $name.
|
||||
*
|
||||
* @throws ezcBasePropertyNotFoundException
|
||||
* If the property does not exist.
|
||||
* @param string $name Name of the property to access.
|
||||
* @return mixed Value of the desired property.
|
||||
* @ignore
|
||||
*/
|
||||
public function __get( $name )
|
||||
{
|
||||
switch ( $name )
|
||||
{
|
||||
case 'mime':
|
||||
return $this->properties['mime'];
|
||||
case 'data':
|
||||
if ( !$this->isAnalyzed )
|
||||
{
|
||||
$this->analyzeImage();
|
||||
}
|
||||
return $this->properties[$name];
|
||||
default:
|
||||
throw new ezcBasePropertyNotFoundException( $name );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the property $name exist and returns the result.
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
* @ignore
|
||||
*/
|
||||
public function __isset( $name )
|
||||
{
|
||||
switch ( $name )
|
||||
{
|
||||
case 'mime':
|
||||
case 'data':
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze the image file's MIME type.
|
||||
* This method triggers a handler to analyze the MIME type of the given image file.
|
||||
*
|
||||
* @throws ezcImageAnalyzerFileNotProcessableException
|
||||
* If the no handler is capable to analyze the given image file.
|
||||
*/
|
||||
public function analyzeType()
|
||||
{
|
||||
if ( !is_array( ezcImageAnalyzer::$availableHandlers ) )
|
||||
{
|
||||
$this->checkHandlers();
|
||||
}
|
||||
foreach ( ezcImageAnalyzer::$availableHandlers as $handler )
|
||||
{
|
||||
if ( ( $mime = $handler->analyzeType( $this->filePath ) ) !== false )
|
||||
{
|
||||
$this->properties['mime'] = $mime;
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new ezcImageAnalyzerFileNotProcessableException( $this->filePath, "Could not determine MIME type of file." );
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze the image file.
|
||||
*
|
||||
* This method triggers a handler to analyze the given image file for more data.
|
||||
*
|
||||
* @throws ezcImageAnalyzerFileNotProcessableException
|
||||
* If the no handler is capable to analyze the given image file.
|
||||
* @throws ezcBaseFileIoException
|
||||
* If an error occurs while the file is read.
|
||||
*/
|
||||
public function analyzeImage()
|
||||
{
|
||||
if ( !is_array( ezcImageAnalyzer::$availableHandlers ) )
|
||||
{
|
||||
$this->checkHandlers();
|
||||
}
|
||||
if ( !isset( $this->properties['mime'] ) )
|
||||
{
|
||||
$this->analyzeType();
|
||||
}
|
||||
foreach ( ezcImageAnalyzer::$availableHandlers as $handler )
|
||||
{
|
||||
if ( $handler->canAnalyze( $this->properties['mime'] ) )
|
||||
{
|
||||
$this->properties['data'] = $handler->analyzeImage( $this->filePath );
|
||||
$this->isAnalyzed = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new ezcImageAnalyzerFileNotProcessableException( $this->filePath, "No handler found to analyze MIME type '{$this->mime}'." );
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* Base exception for the ImageAnalysis package.
|
||||
*
|
||||
* @package ImageAnalysis
|
||||
* @version 1.1.3
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* General exception container for the ImageAnalysis component.
|
||||
*
|
||||
* @package ImageAnalysis
|
||||
* @version 1.1.3
|
||||
*/
|
||||
abstract class ezcImageAnalyzerException extends ezcBaseException
|
||||
{
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the ezcImageAnalyzerFileNotProcessableException.
|
||||
*
|
||||
* @package ImageAnalysis
|
||||
* @version 1.1.3
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* The option name you tried to register is already in use.
|
||||
*
|
||||
* @package ImageAnalysis
|
||||
* @version 1.1.3
|
||||
*/
|
||||
class ezcImageAnalyzerFileNotProcessableException extends ezcImageAnalyzerException
|
||||
{
|
||||
/**
|
||||
* Creates a new ezcImageAnalyzerFileNotProcessableException.
|
||||
*
|
||||
* @param string $file Not processable file.
|
||||
* @param string $reason Reason that the file is not processable.
|
||||
* @return void
|
||||
*/
|
||||
function __construct( $file, $reason = null )
|
||||
{
|
||||
$reasonPart = '';
|
||||
if ( $reason )
|
||||
{
|
||||
$reasonPart = " Reason: $reason.";
|
||||
}
|
||||
parent::__construct( "Could not process file '{$file}'.{$reasonPart}" );
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the ezcImageAnalyzerInvalidHandlerException.
|
||||
*
|
||||
* @package ImageAnalysis
|
||||
* @version 1.1.3
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* A registered handler class does not exist or does not inherit from ezcImageAnalyzerHandler.
|
||||
*
|
||||
* @package ImageAnalysis
|
||||
* @version 1.1.3
|
||||
*/
|
||||
class ezcImageAnalyzerInvalidHandlerException extends ezcImageAnalyzerException
|
||||
{
|
||||
/**
|
||||
* Creates a new ezcImageAnalyzerInvalidHandlerException.
|
||||
*
|
||||
* @param string $handlerClass Invalid class name.
|
||||
* @return void
|
||||
*/
|
||||
function __construct( $handlerClass )
|
||||
{
|
||||
parent::__construct( "The registered handler class '{$handlerClass}' does not exist or does not inherit from ezcImageAnalyzerHandler." );
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,637 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the ezcImageAnalyzerImagemagickHandler class.
|
||||
*
|
||||
* @package ImageAnalysis
|
||||
* @version 1.1.3
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to retrieve 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
|
||||
* {@link 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 {@link ezcImageAnalyzer::setHandlerClasses()}.
|
||||
*
|
||||
* @package ImageAnalysis
|
||||
* @version 1.1.3
|
||||
*/
|
||||
class ezcImageAnalyzerImagemagickHandler extends ezcImageAnalyzerHandler
|
||||
{
|
||||
/**
|
||||
* The ImageMagick binary to utilize.
|
||||
*
|
||||
* This variable is set during call to
|
||||
* {@link ezcImageAnalyzerImagemagickHandler::checkImagemagick()}.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $binary;
|
||||
|
||||
/**
|
||||
* Indicates if this handler is available.
|
||||
*
|
||||
* The first call to
|
||||
* {@link ezcImageAnalyzerImagemagickHandler::isAvailable()}
|
||||
* determines this variable, which is then used as a cache for the call to
|
||||
* {@link ezcImageAnalyzerImagemagickHandler::checkImagemagick()}.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $isAvailable;
|
||||
|
||||
/**
|
||||
* Mapping between ImageMagick identification strings and MIME types.
|
||||
*
|
||||
* ImageMagick's "identify" command returns an identification string to
|
||||
* indicate the file type examined.
|
||||
*
|
||||
* This map has been handcrafted, because ImageMagick misses the
|
||||
* possibility to determine MIME types. It misses some identification
|
||||
* strings (mostly for file types which are absolutely rare in use
|
||||
* or which ImageMagick is only capable to read or write, but not both.).
|
||||
*
|
||||
* @var array(string=>string)
|
||||
*/
|
||||
protected $mimeMap = array(
|
||||
'bmp' => 'image/bmp',
|
||||
'bmp2' => 'image/bmp',
|
||||
'bmp3' => 'image/bmp',
|
||||
'cur' => 'image/x-win-bitmap',
|
||||
'dcx' => 'image/dcx',
|
||||
'epdf' => 'application/pdf',
|
||||
'epi' => 'application/postscript',
|
||||
'eps' => 'application/postscript',
|
||||
'eps2' => 'application/postscript',
|
||||
'eps3' => 'application/postscript',
|
||||
'epsf' => 'application/postscript',
|
||||
'epsi' => 'application/postscript',
|
||||
'ept' => 'application/postscript',
|
||||
'ept2' => 'application/postscript',
|
||||
'ept3' => 'application/postscript',
|
||||
'fax' => 'image/g3fax',
|
||||
'fits' => 'image/x-fits',
|
||||
'g3' => 'image/g3fax',
|
||||
'gif' => 'image/gif',
|
||||
'gif87' => 'image/gif',
|
||||
'icb' => 'application/x-icb',
|
||||
'ico' => 'image/x-win-bitmap',
|
||||
'icon' => 'image/x-win-bitmap',
|
||||
'jng' => 'image/jng',
|
||||
'jpeg' => 'image/jpeg',
|
||||
'jpg' => 'image/jpeg',
|
||||
'm2v' => 'video/mpeg2',
|
||||
'miff' => 'application/x-mif',
|
||||
'mng' => 'video/mng',
|
||||
'mpeg' => 'video/mpeg',
|
||||
'mpg' => 'video/mpeg',
|
||||
'otb' => 'image/x-otb',
|
||||
'p7' => 'image/x-xv',
|
||||
'palm' => 'image/x-palm',
|
||||
'pbm' => 'image/pbm',
|
||||
'pcd' => 'image/pcd',
|
||||
'pcds' => 'image/pcd',
|
||||
'pcl' => 'application/pcl',
|
||||
'pct' => 'image/pict',
|
||||
'pcx' => 'image/x-pcx',
|
||||
'pdb' => 'application/vnd.palm',
|
||||
'pdf' => 'application/pdf',
|
||||
'pgm' => 'image/x-pgm',
|
||||
'picon' => 'image/xpm',
|
||||
'pict' => 'image/pict',
|
||||
'pjpeg' => 'image/pjpeg',
|
||||
'png' => 'image/png',
|
||||
'png24' => 'image/png',
|
||||
'png32' => 'image/png',
|
||||
'png8' => 'image/png',
|
||||
'pnm' => 'image/pbm',
|
||||
'ppm' => 'image/x-ppm',
|
||||
'ps' => 'application/postscript',
|
||||
'psd' => 'image/x-photoshop',
|
||||
'ptif' => 'image/x-ptiff',
|
||||
'ras' => 'image/ras',
|
||||
'sgi' => 'image/sgi',
|
||||
'sun' => 'image/ras',
|
||||
'svg' => 'image/svg+xml',
|
||||
'svgz' => 'image/svg',
|
||||
'text' => 'text/plain',
|
||||
'tga' => 'image/tga',
|
||||
'tif' => 'image/tiff',
|
||||
'tiff' => 'image/tiff',
|
||||
'txt' => 'text/plain',
|
||||
'vda' => 'image/vda',
|
||||
'viff' => 'image/x-viff',
|
||||
'vst' => 'image/vst',
|
||||
'wbmp' => 'image/vnd.wap.wbmp',
|
||||
'xbm' => 'image/x-xbitmap',
|
||||
'xpm' => 'image/x-xbitmap',
|
||||
'xv' => 'image/x-viff',
|
||||
'xwd' => 'image/xwd',
|
||||
);
|
||||
|
||||
/**
|
||||
* MIME types this handler is capable to read.
|
||||
*
|
||||
* This array holds an extract of the
|
||||
* {@link ezcImageAnalyzerHandler::$mimeMap}, listing all MIME types this
|
||||
* handler is capable to analyze. The map is indexed by the MIME type,
|
||||
* assigned to boolean true, to speed up hash lookups.
|
||||
*
|
||||
* @var array(string=>bool)
|
||||
*/
|
||||
protected $mimeTypes = array(
|
||||
'application/pcl' => true,
|
||||
'application/pdf' => true,
|
||||
'application/postscript' => true,
|
||||
'application/vnd.palm' => true,
|
||||
'application/x-icb' => true,
|
||||
'application/x-mif' => true,
|
||||
'image/dcx' => true,
|
||||
'image/g3fax' => true,
|
||||
'image/gif' => true,
|
||||
'image/jng' => true,
|
||||
'image/jpeg' => true,
|
||||
'image/pbm' => true,
|
||||
'image/pcd' => true,
|
||||
'image/pict' => true,
|
||||
'image/pjpeg' => true,
|
||||
'image/png' => true,
|
||||
'image/ras' => true,
|
||||
'image/sgi' => true,
|
||||
'image/svg' => true,
|
||||
'image/tga' => true,
|
||||
'image/tiff' => true,
|
||||
'image/vda' => true,
|
||||
'image/vnd.wap.wbmp' => true,
|
||||
'image/vst' => true,
|
||||
'image/x-fits' => true,
|
||||
'image/x-ms-bmp' => true,
|
||||
'image/x-otb' => true,
|
||||
'image/x-palm' => true,
|
||||
'image/x-pcx' => true,
|
||||
'image/x-pgm' => true,
|
||||
'image/x-photoshop' => true,
|
||||
'image/x-ppm' => true,
|
||||
'image/x-ptiff' => true,
|
||||
'image/x-viff' => true,
|
||||
'image/x-win-bitmap' => true,
|
||||
'image/x-xbitmap' => true,
|
||||
'image/x-xv' => true,
|
||||
'image/xpm' => true,
|
||||
'image/xwd' => true,
|
||||
'text/plain' => true,
|
||||
'video/mng' => true,
|
||||
'video/mpeg' => true,
|
||||
'video/mpeg2' => true,
|
||||
);
|
||||
|
||||
/**
|
||||
* Analyzes the image type.
|
||||
* This method analyzes image data to determine the MIME type. This method
|
||||
* returns the MIME type of the file to analyze in lowercase letters (e.g.
|
||||
* "image/jpeg") or false, if the images MIME type could not be determined.
|
||||
*
|
||||
* For a list of image types this handler will be able to analyze, see
|
||||
* {@link ezcImageAnalyzerImagemagickHandler}.
|
||||
*
|
||||
* @param string $file The file to analyze.
|
||||
* @return string|bool The MIME type if analyzation suceeded or false.
|
||||
*/
|
||||
public function analyzeType( $file )
|
||||
{
|
||||
$parameters = '-format ' . escapeshellarg( '%m|' ) . ' ' . escapeshellarg( $file );
|
||||
$res = ezcImageAnalyzerImagemagickHandler::runCommand( $parameters, $outputString, $errorString );
|
||||
if ( $res !== 0 || $errorString !== '' )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$identifiers = explode( '|', strtolower( $outputString ), 2 );
|
||||
if ( !isset( $this->mimeMap[$identifiers[0]] ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return $this->mimeMap[$identifiers[0]];
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze the image for detailed information.
|
||||
*
|
||||
* This may return various information about the image, depending on it's
|
||||
* type. All information is collected in the struct
|
||||
* {@link ezcImageAnalyzerData}. At least the
|
||||
* {@link ezcImageAnalyzerData::$mime} attribute is always available, if the
|
||||
* image type can be analyzed at all. Additionally this handler will always
|
||||
* set the {@link ezcImageAnalyzerData::$width},
|
||||
* {@link ezcImageAnalyzerData::$height} and
|
||||
* {@link ezcImageAnalyzerData::$size} attributes. For detailes information
|
||||
* on the additional data returned, see {@link ezcImageAnalyzerImagemagickHandler}.
|
||||
*
|
||||
* @todo Why does ImageMagick return the wrong file size on TIFF with comments?
|
||||
* @todo Check for translucent transparency.
|
||||
*
|
||||
* @throws ezcImageAnalyzerFileNotProcessableException
|
||||
* If image file can not be processed.
|
||||
* @param string $file The file to analyze.
|
||||
* @return ezcImageAnalyzerData
|
||||
*/
|
||||
public function analyzeImage( $file )
|
||||
{
|
||||
// Example strings returned here:
|
||||
// JPEG (Exif without comment):
|
||||
// string(45) "[JPEG|76383|399|600|8|59428|DirectClassRGB|]*"
|
||||
// --------------------------------
|
||||
// TIFF (Exif with comment):
|
||||
// string(79) "[TIFF|108125|399|600|8|113524|DirectClassRGB|A simple comment in a TIFF file.]*"
|
||||
// --------------------------------
|
||||
// PNG:
|
||||
// string(46) "[PNG|5420|160|120|8|254|DirectClassRGBMatte|]*"
|
||||
// --------------------------------
|
||||
// GIF (Animated):
|
||||
// string(168) "[GIF|4100|80|50|8|38|PseudoClassRGB|]*[GIF|4100|80|50|8|21|PseudoClassRGB|]*[GIF|4100|80|50|8|17|PseudoClassRGB|Copyright 1996 DeMorgan Industries Corp.
|
||||
//
|
||||
// Animated Cog]*"
|
||||
// --------------------------------
|
||||
|
||||
$command = '-format ' . escapeshellarg( '[%m|%b|%w|%h|%k|%r|%c]*' ) . ' ' . escapeshellarg( $file );
|
||||
|
||||
// Execute ImageMagick
|
||||
$return = $this->runCommand( $command, $outputString, $errorString );
|
||||
if ( $return !== 0 || $errorString !== '' )
|
||||
{
|
||||
throw new ezcImageAnalyzerFileNotProcessableException( $file, "ImageMagick error: '{$errorString}'." );
|
||||
}
|
||||
|
||||
$dataStruct = new ezcImageAnalyzerData();
|
||||
|
||||
$rawDataArr = explode( '*', $outputString );
|
||||
if ( sizeof( $rawDataArr ) === 1 )
|
||||
{
|
||||
throw new ezcImageAnalyzerFileNotProcessableException( $file, "ImageMagick did not return correct formated string." );
|
||||
}
|
||||
|
||||
// Unset last (empty) element
|
||||
unset( $rawDataArr[count( $rawDataArr ) - 1] );
|
||||
|
||||
if ( sizeof( $rawDataArr ) > 1 )
|
||||
{
|
||||
$dataStruct->isAnimated = true;
|
||||
}
|
||||
foreach ( $rawDataArr as $id => $rawData )
|
||||
{
|
||||
$parsedData = explode( '|', substr( $rawData, 1, -1 ) );
|
||||
$dataStruct->mime = $this->mimeMap[strtolower( $parsedData[0] )];
|
||||
|
||||
$dataStruct->size = filesize( $file );
|
||||
|
||||
$dataStruct->width = max( (int) $parsedData[2], $dataStruct->width );
|
||||
$dataStruct->height = max( (int) $parsedData[3], $dataStruct->height );
|
||||
|
||||
$dataStruct->isColor = $parsedData[4] > 2 ? true : false;
|
||||
|
||||
$dataStruct->transparencyType = self::TRANSPARENCY_OPAQUE;
|
||||
if ( strpos( $parsedData[5], 'RGBMatte' ) !== FALSE )
|
||||
{
|
||||
$dataStruct->transparencyType = self::TRANSPARENCY_TRANSPARENT;
|
||||
}
|
||||
|
||||
if ( $parsedData[6] !== '' )
|
||||
{
|
||||
if ( $dataStruct->isAnimated && $id > 0 )
|
||||
{
|
||||
$dataStruct->commentList[] = $parsedData[6];
|
||||
}
|
||||
else
|
||||
{
|
||||
$dataStruct->comment = $parsedData[6];
|
||||
$dataStruct->commentList = array( $parsedData[6] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $dataStruct->mime === 'image/jpeg' || $dataStruct->mime === 'image/tiff' )
|
||||
{
|
||||
$this->analyzeExif( $dataStruct, $file );
|
||||
}
|
||||
}
|
||||
return $dataStruct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze Exif data contained in JPEG and TIFF images.
|
||||
*
|
||||
* This method analyzes the Exif data contained in JPEG and TIFF images,
|
||||
* using ImageMagick's "identify" binary.
|
||||
*
|
||||
* This method tries to provide the EXIF data in a format as close as
|
||||
* possible to the format returned by ext/EXIF {@link http://php.net/exif}.
|
||||
*
|
||||
* @param ezcImageAnalyzerData $data The data object to fill.
|
||||
* @param string $file The file to analyze.
|
||||
*/
|
||||
protected function analyzeExif( ezcImageAnalyzerData $data, $file )
|
||||
{
|
||||
$tagMap = array(
|
||||
"IFD0" => array(
|
||||
"ImageDescription",
|
||||
"Make",
|
||||
"Model",
|
||||
"Orientation",
|
||||
"XResolution",
|
||||
"YResolution",
|
||||
"ResolutionUnit",
|
||||
"Software",
|
||||
"DateTime",
|
||||
"YCbCrPositioning",
|
||||
"Exif_IFD_Pointer",
|
||||
"Copyright",
|
||||
"UserComment",
|
||||
),
|
||||
|
||||
"EXIF" => array(
|
||||
"ExposureTime",
|
||||
"FNumber",
|
||||
"ExposureProgram",
|
||||
"ISOSpeedRatings",
|
||||
"ExifVersion",
|
||||
"DateTimeOriginal",
|
||||
"DateTimeDigitized",
|
||||
"ComponentsConfiguration",
|
||||
"BrightnessValue",
|
||||
"ExposureBiasValue",
|
||||
"MaxApertureValue",
|
||||
"MeteringMode",
|
||||
"LightSource",
|
||||
"Flash",
|
||||
"FocalLength",
|
||||
// ImageMagick does not grab this correct, therefore not supported
|
||||
// "SubjectLocation",
|
||||
"MakerNote",
|
||||
"UserComment",
|
||||
"FlashPixVersion",
|
||||
"ColorSpace",
|
||||
"ExifImageWidth",
|
||||
"ExifImageLength",
|
||||
"InteroperabilityOffset",
|
||||
"FileSource",
|
||||
"SceneType",
|
||||
"CustomRendered",
|
||||
"ExposureMode",
|
||||
"WhiteBalance",
|
||||
"DigitalZoomRatio",
|
||||
"FocalLengthIn35mmFilm",
|
||||
"SceneCaptureType",
|
||||
"GainControl",
|
||||
"Contrast",
|
||||
"Saturation",
|
||||
"Sharpness",
|
||||
"SubjectDistanceRange",
|
||||
),
|
||||
"INTEROP" => array(
|
||||
"InterOperabilityIndex",
|
||||
"InterOperabilityVersion"
|
||||
)
|
||||
);
|
||||
|
||||
// Retreive exif data
|
||||
$command = '-format ' . escapeshellarg( "%[EXIF:*]" ) . ' ' . escapeshellarg( $file );
|
||||
$return = $this->runCommand( $command, $outputString, $errorString, false );
|
||||
if ( $return !== 0 || $errorString !== '' )
|
||||
{
|
||||
throw new ezcImageAnalyzerFileNotProcessableException( $file, "ImageMagick error: '{$errorString}'." );
|
||||
}
|
||||
|
||||
// The following is done in 2 steps to ensure the same array order as ext/exif provides.
|
||||
|
||||
// Pre-process data
|
||||
$rawData = explode( "\n", $outputString );
|
||||
$dataArr = array();
|
||||
foreach ( $rawData as $dataString )
|
||||
{
|
||||
$dataParts = explode( "=", $dataString, 2 );
|
||||
if ( sizeof( $dataParts ) === 2 )
|
||||
{
|
||||
$dataArr[$dataParts[0]] = substr( $dataParts[1], -1, 1 ) === "." ? substr( $dataParts[1], 0, -1 ) : $dataParts[1];
|
||||
}
|
||||
}
|
||||
// Some post-processing is needed because ext/exif has some different tag names
|
||||
if ( isset( $dataArr["ExifOffset"] ) )
|
||||
{
|
||||
$dataArr["Exif_IFD_Pointer"] = $dataArr["ExifOffset"];
|
||||
}
|
||||
if ( isset( $dataArr["InteroperabilityIndex"] ) )
|
||||
{
|
||||
$dataArr["InterOperabilityIndex"] = $dataArr["InteroperabilityIndex"];
|
||||
}
|
||||
if ( isset( $dataArr["InteroperabilityVersion"] ) )
|
||||
{
|
||||
$dataArr["InterOperabilityVersion"] = $dataArr["InteroperabilityVersion"];
|
||||
}
|
||||
if ( isset( $dataArr["Artist"] ) )
|
||||
{
|
||||
$dataArr["Author"] = $dataArr["Artist"];
|
||||
}
|
||||
|
||||
// Assign data to tags
|
||||
$exifArr = array();
|
||||
foreach ( $tagMap as $section => $tags )
|
||||
{
|
||||
foreach ( $tags as $tag )
|
||||
{
|
||||
if ( isset( $dataArr[$tag] ) )
|
||||
{
|
||||
// Correct types
|
||||
switch ( true )
|
||||
{
|
||||
case ( ctype_digit( $dataArr[$tag] ) && stripos( $tag, "version" ) === false ):
|
||||
$exifArr[$section][$tag] = (int)$dataArr[$tag];
|
||||
break;
|
||||
case ( is_numeric( $dataArr[$tag] ) && stripos( $tag, "version" ) === false ):
|
||||
$exifArr[$section][$tag] = (float)$dataArr[$tag];
|
||||
break;
|
||||
default:
|
||||
$exifArr[$section][$tag] = $dataArr[$tag];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Retreive additional data for computation
|
||||
$imageData = getimagesize( $file );
|
||||
|
||||
$colorCount = 0;
|
||||
$command = '-format ' . escapeshellarg( '%k' ) . ' ' . escapeshellarg( $file );
|
||||
$return = $this->runCommand( $command, $colorCount, $errorString );
|
||||
if ( $return !== 0 || $errorString !== '' )
|
||||
{
|
||||
throw new ezcImageAnalyzerFileNotProcessableException( $file, "ImageMagick error: '{$errorString}'." );
|
||||
}
|
||||
|
||||
// Compute additional section ext/EXIF provides
|
||||
$additionsArr = array();
|
||||
$addtionsArr["FILE"]["FileName"] = basename( $file );
|
||||
$addtionsArr["FILE"]["FileDateTime"] = filemtime( $file );
|
||||
$addtionsArr["FILE"]["FileSize"] = filesize( $file );
|
||||
$addtionsArr["FILE"]["FileType"] = $imageData[2];
|
||||
$addtionsArr["FILE"]["MimeType"] = $data->mime;
|
||||
$addtionsArr["FILE"]["SectionsFound"] =
|
||||
( isset( $exifArr["EXIF"] ) || isset( $exifArr["IFD0"] ) ? "ANY_TAG, " : "" )
|
||||
. implode( ", ", array_keys( $exifArr ) );
|
||||
|
||||
$addtionsArr["COMPUTED"]["html"] = "width=\"{$data->width}\" height=\"{$data->height}\"";
|
||||
$addtionsArr["COMPUTED"]["Height"] = $data->height;
|
||||
$addtionsArr["COMPUTED"]["Width"] = $data->width;
|
||||
$addtionsArr["COMPUTED"]["IsColor"] = ( $colorCount < 3 ) ? 0 : 1;
|
||||
|
||||
// @todo Implement if possible!
|
||||
// $addtionsArr["COMPUTED"]["ByteOrderMotorola"] = null;
|
||||
|
||||
$fNumberParts = isset( $exifArr["EXIF"]["FNumber"] ) ? explode( "/", $exifArr["EXIF"]["FNumber"] ) : null;
|
||||
if ( sizeof( $fNumberParts ) === 2 )
|
||||
{
|
||||
$addtionsArr["COMPUTED"]["ApertureFNumber"] = sprintf( "f/%.1f", $fNumberParts[0] / $fNumberParts[1] );
|
||||
}
|
||||
// ImageMagick resturns "..." for not set comments
|
||||
if ( isset( $exifArr["EXIF"]["UserComment"] ) )
|
||||
{
|
||||
$addtionsArr["COMPUTED"]["UserComment"] = preg_match( "/^\.*$/", $exifArr["EXIF"]["UserComment"] ) === false ? $exifArr["EXIF"]["UserComment"] : null;
|
||||
// @todo Maybe we can determine that somehow?
|
||||
// $addtionsArr["COMPUTED"]["UserCommentEncoding"] = "UNDEFINED";
|
||||
}
|
||||
|
||||
// Not available through ImageMagick
|
||||
// $addtionsArr["COMPUTED"]["Thumbnail.FileType"] = null
|
||||
// $addtionsArr["COMPUTED"]["Thumbnail.MimeType"] = null
|
||||
|
||||
// Merge arrays (done here, to have consistent key order)
|
||||
$data->exif = array_merge( $addtionsArr, $exifArr );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {@link 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.
|
||||
*/
|
||||
public function canAnalyze( $mime )
|
||||
{
|
||||
return isset( $this->mimeTypes[strtolower( $mime )] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks wether the GD handler is available on the system.
|
||||
*
|
||||
* Returns if PHP's {@link getimagesize()} function is available.
|
||||
*
|
||||
* @return bool True is the handler is available.
|
||||
*/
|
||||
public function isAvailable()
|
||||
{
|
||||
if ( !isset( $this->isAvailable ) )
|
||||
{
|
||||
$this->isAvailable = $this->checkImagemagick();
|
||||
}
|
||||
return $this->isAvailable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the availability of ImageMagick on the system.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function checkImagemagick()
|
||||
{
|
||||
if ( !isset( $this->options['binary'] ) )
|
||||
{
|
||||
switch ( PHP_OS )
|
||||
{
|
||||
case 'Linux':
|
||||
case 'Unix':
|
||||
case 'FreeBSD':
|
||||
case 'MacOS':
|
||||
case 'Darwin':
|
||||
case 'SunOS':
|
||||
$this->binary = 'identify';
|
||||
break;
|
||||
case 'Windows':
|
||||
case 'WINNT':
|
||||
case 'WIN32':
|
||||
$this->binary = 'identify.exe';
|
||||
break;
|
||||
default:
|
||||
throw new ezcImageAnalyzerInvalidHandlerException( 'ezcImageAnalyzerImagemagickHandler' );
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->binary = $this->options['binary'];
|
||||
}
|
||||
|
||||
return ezcBaseFeatures::hasImageIdentify();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the binary registered in ezcImageAnalyzerImagemagickHandler::$binary.
|
||||
*
|
||||
* This method executes the ImageMagick binary using the applied parameter
|
||||
* string. It returns the return value of the command. The output printed
|
||||
* to STDOUT and ERROUT is available through the $stdOut and $errOut
|
||||
* parameters.
|
||||
*
|
||||
* @param string $parameters The parameters for the binary to execute.
|
||||
* @param string $stdOut The standard output.
|
||||
* @param string $errOut The error output.
|
||||
* @param bool $stripNewlines Wether to strip the newlines from STDOUT.
|
||||
* @return int The return value of the command (0 on success).
|
||||
*/
|
||||
protected function runCommand( $parameters, &$stdOut, &$errOut, $stripNewlines = true )
|
||||
{
|
||||
$command = escapeshellcmd( $this->binary ) . ( $parameters !== '' ? ' ' . $parameters : '' );
|
||||
// Prepare to run ImageMagick command
|
||||
$descriptors = array(
|
||||
array( 'pipe', 'r' ),
|
||||
array( 'pipe', 'w' ),
|
||||
array( 'pipe', 'w' ),
|
||||
);
|
||||
|
||||
// Open ImageMagick process
|
||||
$process = proc_open( $command, $descriptors, $pipes );
|
||||
|
||||
// Close STDIN pipe
|
||||
fclose( $pipes[0] );
|
||||
|
||||
// Read STDOUT
|
||||
$stdOut = '';
|
||||
do
|
||||
{
|
||||
$stdOut .= ( $stripNewlines === true ) ? rtrim( fgets( $pipes[1], 1024), "\n" ) : fgets( $pipes[1], 1024 );
|
||||
} while ( !feof( $pipes[1] ) );
|
||||
|
||||
// Read STDERR
|
||||
$errOut = '';
|
||||
do
|
||||
{
|
||||
$errOut .= rtrim( fgets( $pipes[2], 1024), "\n" );
|
||||
} while ( !feof( $pipes[2] ) );
|
||||
|
||||
// Wait for process to terminate and store return value
|
||||
return proc_close( $process );
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,458 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the ezcImageAnalyzerPhpHandler class.
|
||||
*
|
||||
* @package ImageAnalysis
|
||||
* @version 1.1.3
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to retrieve information about a given image file.
|
||||
* This handler implements image analyzation using direct PHP functionality,
|
||||
* mainly the {@link getimagesize()} function and, if available, the EXIF
|
||||
* extension {@link exif_read_data()}. The driver is capable of determining
|
||||
* the type the following file formats:
|
||||
*
|
||||
* - GIF
|
||||
* - JPG
|
||||
* - PNG
|
||||
* - SWF
|
||||
* - SWC
|
||||
* - PSD
|
||||
* - TIFF
|
||||
* - BMP
|
||||
* - IFF
|
||||
* - JP2
|
||||
* - JPX
|
||||
* - JB2
|
||||
* - JPC
|
||||
* - XBM
|
||||
* - WBMP
|
||||
*
|
||||
* The driver determines the MIME type of these images (using the
|
||||
* {@link ezcImageAnalyzerPhpHandler::analyzeType()} method). The width,
|
||||
* height and size of the given image are always available after analyzing a
|
||||
* file, if the file in general can be analyzed
|
||||
* {@link ezcImageAnalyzerPhpHandler::canAnalyze()}.
|
||||
*
|
||||
* For JPEG and TIFF images this driver will try to read in information using
|
||||
* the EXIF extension in PHP and fills in the following properties of the
|
||||
* {@link ezcImageAnalyzerData} struct, returned by the
|
||||
* {@link ezcImageAnalyzerPhpHandler::analyzeImage()} method:
|
||||
* - exif
|
||||
* - isColor
|
||||
* - comment
|
||||
* - copyright
|
||||
* - date
|
||||
* - hasThumbnail
|
||||
* - isAnimated
|
||||
*
|
||||
* For GIF (also animated) it finds information by scanning the file manually
|
||||
* and fills in the following properties of the
|
||||
* {@link ezcImageAnalyzerData} struct, returned by the
|
||||
* {@link ezcImageAnalyzerPhpHandler::analyzeImage()} method:
|
||||
* - mode
|
||||
* - transparencyType
|
||||
* - comment
|
||||
* - commentList
|
||||
* - colorCount
|
||||
* - isAnimated
|
||||
*
|
||||
* @package ImageAnalysis
|
||||
* @version 1.1.3
|
||||
*/
|
||||
class ezcImageAnalyzerPhpHandler extends ezcImageAnalyzerHandler
|
||||
{
|
||||
/**
|
||||
* Analyzes the image type.
|
||||
*
|
||||
* This method analyzes image data to determine the MIME type. This method
|
||||
* returns the MIME type of the file to analyze in lowercase letters (e.g.
|
||||
* "image/jpeg") or false, if the images MIME type could not be determined.
|
||||
*
|
||||
* For a list of image types this handler will be able to analyze, see
|
||||
* {@link ezcImageAnalyzerPhpHandler}.
|
||||
*
|
||||
* @param string $file The file to analyze.
|
||||
* @return string|bool The MIME type if analyzation suceeded or false.
|
||||
*/
|
||||
public function analyzeType( $file )
|
||||
{
|
||||
$data = getimagesize( $file );
|
||||
if ( $data === false )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return image_type_to_mime_type( $data[2] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze the image for detailed information.
|
||||
*
|
||||
* This may return various information about the image, depending on it's
|
||||
* type. All information is collected in the struct
|
||||
* {@link ezcImageAnalyzerData}. At least the
|
||||
* {@link ezcImageAnalyzerData::$mime} attribute is always available, if the
|
||||
* image type can be analyzed at all. Additionally this handler will always
|
||||
* set the {@link ezcImageAnalyzerData::$width},
|
||||
* {@link ezcImageAnalyzerData::$height} and
|
||||
* {@link ezcImageAnalyzerData::$size} attributes. For detailes information
|
||||
* on the additional data returned, see {@link ezcImageAnalyzerPhpHandler}.
|
||||
*
|
||||
* @throws ezcImageAnalyzerFileNotProcessableException
|
||||
* If image file can not be processed.
|
||||
* @param string $file The file to analyze.
|
||||
* @return ezcImageAnalyzerData
|
||||
*/
|
||||
public function analyzeImage( $file )
|
||||
{
|
||||
$data = getimagesize( $file );
|
||||
if ( $data === false )
|
||||
{
|
||||
throw new ezcImageAnalyzerFileNotProcessableException( $file, 'getimagesize() returned false.' );
|
||||
}
|
||||
|
||||
$dataStruct = new ezcImageAnalyzerData();
|
||||
$dataStruct->width = $data[0];
|
||||
$dataStruct->height = $data[1];
|
||||
$dataStruct->mime = image_type_to_mime_type( $data[2] );
|
||||
$dataStruct->size = filesize( $file );
|
||||
|
||||
if ( ( $dataStruct->mime === 'image/jpeg' || $dataStruct->mime === 'image/tiff' )
|
||||
&& ezcBaseFeatures::hasFunction( 'exif_read_data')
|
||||
)
|
||||
{
|
||||
$this->analyzeExif( $file, $dataStruct );
|
||||
}
|
||||
elseif ( $dataStruct->mime === 'image/gif' )
|
||||
{
|
||||
$this->analyzeGif( $file, $dataStruct );
|
||||
}
|
||||
|
||||
return $dataStruct;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {@link self::analyzeImage()} method.
|
||||
*
|
||||
* @param string $mime The MIME type to check for.
|
||||
* @return bool True if the handler is able to analyze the MIME type.
|
||||
*/
|
||||
public function canAnalyze( $mime )
|
||||
{
|
||||
switch ( $mime )
|
||||
{
|
||||
case 'image/gif':
|
||||
case 'image/jpeg':
|
||||
case 'image/png':
|
||||
case 'image/psd':
|
||||
case 'image/bmp':
|
||||
case 'image/tiff':
|
||||
case 'image/tiff':
|
||||
case 'image/jp2':
|
||||
case 'application/x-shockwave-flash':
|
||||
case 'image/iff':
|
||||
case 'image/vnd.wap.wbmp':
|
||||
case 'image/xbm':
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks wether the GD handler is available on the system.
|
||||
*
|
||||
* Returns if PHP's {@link getimagesize()} function is available.
|
||||
*
|
||||
* @return bool True is the handler is available.
|
||||
*/
|
||||
public function isAvailable()
|
||||
{
|
||||
return ezcBaseFeatures::hasFunction( 'getimagesize' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze EXIF enabled file format for EXIF data entries.
|
||||
*
|
||||
* The image file is analyzed by calling exif_read_data and placing the
|
||||
* result in self::exif. In addition it fills in extra properties from
|
||||
* the EXIF data for easy and uniform access.
|
||||
*
|
||||
* @param string $file The file to analyze.
|
||||
* @param ezcImageAnalyzerData $dataStruct The data struct to fill.
|
||||
* @return ezcImageAnalyzerData The filled data struct.
|
||||
*/
|
||||
private function analyzeExif( $file, ezcImageAnalyzerData $dataStruct )
|
||||
{
|
||||
$dataStruct->exif = exif_read_data( $file, "COMPUTED,FILE", true, false );
|
||||
|
||||
// Section "COMPUTED"
|
||||
if ( isset( $dataStruct->exif['COMPUTED']['Width'] ) && isset( $dataStruct->exif['COMPUTED']['Height'] ) )
|
||||
{
|
||||
$dataStruct->width = $dataStruct->exif['COMPUTED']['Width'];
|
||||
$dataStruct->height = $dataStruct->exif['COMPUTED']['Height'];
|
||||
}
|
||||
if ( isset( $dataStruct->exif['COMPUTED']['IsColor'] ) )
|
||||
{
|
||||
$dataStruct->isColor = $dataStruct->exif['COMPUTED']['IsColor'] == 1;
|
||||
}
|
||||
if ( isset( $dataStruct->exif['COMPUTED']['UserComment'] ) )
|
||||
{
|
||||
$dataStruct->comment = $dataStruct->exif['COMPUTED']['UserComment'];
|
||||
$dataStruct->commentList = array( $dataStruct->comment );
|
||||
}
|
||||
if ( isset( $dataStruct->exif['COMPUTED']['Copyright'] ) )
|
||||
{
|
||||
$dataStruct->copyright = $dataStruct->exif['COMPUTED']['Copyright'];
|
||||
}
|
||||
|
||||
// Section THUMBNAIL
|
||||
$dataStruct->hasThumbnail = isset( $dataStruct->exif['THUMBNAIL'] );
|
||||
|
||||
// Section "FILE"
|
||||
if ( isset( $dataStruct->exif['FILE']['FileSize'] ) )
|
||||
{
|
||||
$dataStruct->size = $dataStruct->exif['FILE']['FileSize'];
|
||||
}
|
||||
if ( isset( $dataStruct->exif['FILE']['FileDateTime'] ) )
|
||||
{
|
||||
$dataStruct->date = $dataStruct->exif['FILE']['FileDateTime'];
|
||||
}
|
||||
|
||||
// EXIF based image are never animated.
|
||||
$dataStruct->isAnimated = false;
|
||||
|
||||
return $dataStruct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze GIF files for detailed information.
|
||||
*
|
||||
* The GIF file is analyzed by scanning for frame entries, if more than one
|
||||
* is found it is assumed to be animated.
|
||||
* It also extracts other information such as image width and height, color
|
||||
* count, image mode, transparency type and comments.
|
||||
*
|
||||
* @throws ezcBaseFileIoException
|
||||
* If image file could not be read.
|
||||
* @throws ezcImageAnalyzerFileNotProcessableException
|
||||
* If image file can not be processed.
|
||||
* @param string $file The file to analyze.
|
||||
* @param ezcImageAnalyzerData $dataStruct The data struct to fill.
|
||||
* @return ezcImageAnalyzerData The filled data struct.
|
||||
*/
|
||||
private function analyzeGif( $file, ezcImageAnalyzerData $dataStruct )
|
||||
{
|
||||
if ( ( $fp = fopen( $file, 'rb' ) ) === false )
|
||||
{
|
||||
throw new ezcBaseFileIoException( $file, ezcBaseFileException::READ );
|
||||
}
|
||||
|
||||
// Read GIF header
|
||||
$magic = fread( $fp, 6 );
|
||||
$offset = 6;
|
||||
if ( $magic != 'GIF87a' &&
|
||||
$magic != 'GIF89a' )
|
||||
{
|
||||
throw new ezcImageAnalyzerFileNotProcessableException( $file, 'Not a valid GIF image file' );
|
||||
}
|
||||
|
||||
$info = array();
|
||||
|
||||
$version = substr( $magic, 3 );
|
||||
$frames = 0;
|
||||
// Gifs are always indexed
|
||||
$dataStruct->mode = self::MODE_INDEXED;
|
||||
$dataStruct->commentList = array();
|
||||
$dataStruct->transparencyType = self::TRANSPARENCY_OPAQUE;
|
||||
|
||||
// Read Logical Screen Descriptor
|
||||
$data = unpack( "v1width/v1height/C1bitfield/C1index/C1ration", fread( $fp, 7 ) );
|
||||
$offset += 7;
|
||||
|
||||
$lsdFields = $data['bitfield'];
|
||||
$globalColorCount = 0;
|
||||
$globalColorTableSize = 0;
|
||||
if ( $lsdFields >> 7 )
|
||||
{
|
||||
// Extract 3 bits for color count
|
||||
$globalColorCount = ( 1 << ( ( $lsdFields & 0x07 ) + 1) );
|
||||
// Each color entry is RGB ie. 3 bytes
|
||||
$globalColorTableSize = $globalColorCount * 3;
|
||||
}
|
||||
|
||||
$dataStruct->colorCount = $globalColorCount;
|
||||
$dataStruct->width = $data['width'];
|
||||
$dataStruct->height = $data['height'];
|
||||
|
||||
if ( $globalColorTableSize )
|
||||
{
|
||||
// Skip the color table, we don't need the data
|
||||
fseek( $fp, $globalColorTableSize, SEEK_CUR );
|
||||
$offset += $globalColorTableSize;
|
||||
}
|
||||
|
||||
$done = false;
|
||||
// Iterate over all blocks and extract information
|
||||
while ( !$done )
|
||||
{
|
||||
$data = fread( $fp, 1 );
|
||||
$offset += 1;
|
||||
$blockType = ord( $data[0] );
|
||||
|
||||
if ( $blockType == 0x21 ) // Extension Introducer
|
||||
{
|
||||
$data .= fread( $fp, 1 );
|
||||
$offset += 1;
|
||||
$extensionLabel = ord( $data[1] );
|
||||
|
||||
if ( $extensionLabel == 0xf9 ) // Graphical Control Extension
|
||||
{
|
||||
$data = unpack( "C1blocksize/C1bitfield/v1delay/C1index/C1term", fread( $fp, 5 + 1 ) );
|
||||
$gceFlags = $data['bitfield'];//ord( $data[1] );
|
||||
// $animationTimer is currently not in use.
|
||||
/* $animationTimer = $data['delay']; */
|
||||
|
||||
// Check bit 0
|
||||
if ( $gceFlags & 0x01 )
|
||||
{
|
||||
$dataStruct->transparencyType = self::TRANSPARENCY_TRANSPARENT;
|
||||
}
|
||||
$offset += 5 + 1;
|
||||
}
|
||||
else if ( $extensionLabel == 0xff ) // Application Extension
|
||||
{
|
||||
$data = fread( $fp, 12 );
|
||||
$offset += 12;
|
||||
|
||||
$dataBlockDone = false;
|
||||
while ( !$dataBlockDone )
|
||||
{
|
||||
$data = unpack( "C1blocksize", fread( $fp, 1 ) );
|
||||
$offset += 1;
|
||||
$blockBytes = $data['blocksize'];
|
||||
|
||||
if ( $blockBytes )
|
||||
{
|
||||
// Skip application data, we don't need the data
|
||||
fseek( $fp, $blockBytes, SEEK_CUR );
|
||||
$offset += $blockBytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
$dataBlockDone = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( $extensionLabel == 0xfe ) // Comment Extension
|
||||
{
|
||||
$commentBlockDone = false;
|
||||
$comment = false;
|
||||
|
||||
while ( !$commentBlockDone )
|
||||
{
|
||||
$data = unpack( "C1blocksize", fread( $fp, 1 ) );
|
||||
$offset += 1;
|
||||
$blockBytes = $data['blocksize'];
|
||||
|
||||
if ( $blockBytes )
|
||||
{
|
||||
// Append current block to comment
|
||||
$data = fread( $fp, $blockBytes );
|
||||
$comment .= $data;
|
||||
$offset += $blockBytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
$commentBlockDone = true;
|
||||
}
|
||||
}
|
||||
if ( $comment )
|
||||
{
|
||||
if ( $dataStruct->comment === null )
|
||||
{
|
||||
$dataStruct->comment = $comment;
|
||||
}
|
||||
$dataStruct->commentList[] = $comment;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ezcImageAnalyzerFileNotProcessableException( $file, "Invalid extension label 0x" . hexdec( $extensionLabel ) . " in GIF image." );
|
||||
}
|
||||
}
|
||||
else if ( $blockType == 0x2c ) // Image Descriptor
|
||||
{
|
||||
++$frames;
|
||||
$data .= fread( $fp, 9 );
|
||||
$data = unpack( "C1separator/v1leftpos/v1toppos/v1width/v1height/C1bitfield", $data );
|
||||
$localColorTableSize = 0;
|
||||
$localColorCount = 0;
|
||||
$idFields = $data['bitfield'];
|
||||
if ( $idFields >> 7 ) // Local Color Table
|
||||
{
|
||||
// Extract 3 bits for color count
|
||||
$localColorCount = ( 1 << ( ( $idFields & 0x07 ) + 1) );
|
||||
// Each color entry is RGB ie. 3 bytes
|
||||
$localColorTableSize = $localColorCount * 3;
|
||||
}
|
||||
if ( $localColorCount > $globalColorCount )
|
||||
{
|
||||
$dataStruct->colorCount = $localColorCount;
|
||||
}
|
||||
|
||||
if ( $localColorTableSize )
|
||||
{
|
||||
// Skip the color table, we don't need the data
|
||||
fseek( $fp, $localColorTableSize, SEEK_CUR );
|
||||
$offset += $localColorTableSize;
|
||||
}
|
||||
|
||||
$lzwCodeSize = fread( $fp, 1 ); // LZW Minimum Code Size, currently unused
|
||||
$offset += 1;
|
||||
|
||||
$dataBlockDone = false;
|
||||
while ( !$dataBlockDone )
|
||||
{
|
||||
$data = unpack( "C1blocksize", fread( $fp, 1 ) );
|
||||
$offset += 1;
|
||||
$blockBytes = $data['blocksize'];
|
||||
|
||||
if ( $blockBytes )
|
||||
{
|
||||
// Skip image data, we don't need the data
|
||||
fseek( $fp, $blockBytes, SEEK_CUR );
|
||||
$offset += $blockBytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
$dataBlockDone = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( $blockType == 0x3b ) // Trailer, end of stream
|
||||
{
|
||||
$done = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ezcImageAnalyzerFileNotProcessableException( $file, "Invalid block type 0x" . hexdec( $blockType ) . " in GIF image." );
|
||||
}
|
||||
if ( feof( $fp ) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
$dataStruct->isAnimated = $frames > 1;
|
||||
|
||||
return $dataStruct;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the ezcImageAnalyzerHandler class.
|
||||
*
|
||||
* @package ImageAnalysis
|
||||
* @version 1.1.3
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
/**
|
||||
* This base class has to be extended by all ezcImageAnalyzerHandler classes.
|
||||
* An object of an ezcImageAnalyzerHandler class must implement this interface
|
||||
* to work properly as a handler for ezcImageAnalyzer.
|
||||
*
|
||||
* @package ImageAnalysis
|
||||
* @version 1.1.3
|
||||
*/
|
||||
abstract class ezcImageAnalyzerHandler
|
||||
{
|
||||
/**
|
||||
* Image is built with a palette and consists of indexed values per pixel.
|
||||
*/
|
||||
const MODE_INDEXED = 1;
|
||||
|
||||
/**
|
||||
* Image consists of RGB value per pixel.
|
||||
*/
|
||||
const MODE_TRUECOLOR = 2;
|
||||
|
||||
/**
|
||||
* No parts of image is transparent.
|
||||
*/
|
||||
const TRANSPARENCY_OPAQUE = 1;
|
||||
|
||||
/*
|
||||
* Selected palette entries are completely see-through.
|
||||
*/
|
||||
const TRANSPARENCY_TRANSPARENT = 2;
|
||||
|
||||
/**
|
||||
* Transparency determined pixel per pixel with a fuzzy value.
|
||||
*/
|
||||
const TRANSPARENCY_TRANSLUCENT = 3;
|
||||
|
||||
/**
|
||||
* Options for the handler.
|
||||
*
|
||||
* Usually this is empty, but some handlers need special options
|
||||
* e.g. {@link ezcImageAnalyzerImagemagickHandler}.
|
||||
*
|
||||
* @var array(string=>mixed)
|
||||
*/
|
||||
protected $options = array();
|
||||
|
||||
/**
|
||||
* Create an ezcImageAnalyzerHandler to analyze a file.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @throws ezcImageAnalyzerException
|
||||
* If the handler is not able to work.
|
||||
* @param array $options Possible options for the handler.
|
||||
*/
|
||||
public function __construct( array $options = array() )
|
||||
{
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks wether the given handler is available for analyzing images.
|
||||
*
|
||||
* Each ezcImageAnalyzerHandler must implement this method in order to
|
||||
* check if the handler is available on the system. The method has to
|
||||
* return true, if the handle is currently available to analyze images
|
||||
* (e.g. if the GD extension is available, for the
|
||||
* {@link ezcImageAnalyzerPhpHandler}).
|
||||
*
|
||||
* @return bool True if the handler is available.
|
||||
*/
|
||||
abstract public function isAvailable();
|
||||
|
||||
/**
|
||||
* Analyzes the image type.
|
||||
*
|
||||
* This method analyzes image data to determine the MIME type. Each
|
||||
* ezcImageAnalyzerHandler must at least be capable of performing this
|
||||
* operation on a file. This method has to return the MIME type of the
|
||||
* file to analyze in lowercase letters (e.g. "image/jpeg") or false, if
|
||||
* the images MIME type could not be determined.
|
||||
*
|
||||
* @param string $file The file to analyze.
|
||||
* @return string|bool The MIME type if analyzation suceeded or false.
|
||||
*/
|
||||
abstract public function analyzeType( $file );
|
||||
|
||||
/**
|
||||
* Analyze the image for detailed information.
|
||||
*
|
||||
* This may return various information about the image, depending on it's
|
||||
* type and the implemented facilities of the handler. All information is
|
||||
* collected in the struct {@link ezcImageAnalyzerData}. Which information
|
||||
* is set about an image in the returned data struct, depends on the image
|
||||
* type and the capabilities of the handler. At least the
|
||||
* {@link ezcImageAnalyzerData::$mime} attribute must be set. Most handlers
|
||||
* also provide additional information like the image dimensions and the size
|
||||
* of the image file.
|
||||
*
|
||||
* @throws ezcImageAnalyzerFileNotProcessableException
|
||||
* If image file can not be processed.
|
||||
* @param string $file The file to analyze.
|
||||
* @return ezcImageAnalyzerData
|
||||
*/
|
||||
abstract public function analyzeImage( $file );
|
||||
|
||||
/**
|
||||
* 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 {@link self::analyzeImage()} method.
|
||||
*
|
||||
* @param string $mime The MIME type to check for.
|
||||
* @return bool True if the handler is able to analyze the MIME type.
|
||||
*/
|
||||
abstract public function canAnalyze( $mime );
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
/**
|
||||
* File containing the ezcImageAnalyzerData struct.
|
||||
*
|
||||
* @package ImageAnalysis
|
||||
* @version 1.1.3
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
/**
|
||||
* Struct to store the data retrieved from an image analysis.
|
||||
*
|
||||
* This class is used as a struct for the data retrieved from
|
||||
* an {@link ezcImageAnalyzerHandler}. It stores various information about
|
||||
* an analyzed image and pre-fills it's attributes with sensible default
|
||||
* values, to make the usage as easy as possible.
|
||||
*
|
||||
* Ths struct class should not be accessed directly (except form
|
||||
* {@link ezcImageAnalyzerHandler} classes, where it is created). From a
|
||||
* users view it is transparently accessable through
|
||||
* {@link ezcImageAnalyzer::$data}, more specific using
|
||||
* <code>
|
||||
* $analyzer = new ezcImageAnalyzer( 'myfile.jpg' );
|
||||
* echo $analyzer->data->size;
|
||||
* </code>
|
||||
*
|
||||
* @see ezcImageAnalyzer
|
||||
* @see ezcImageAnalyzerHandler
|
||||
*
|
||||
* @package ImageAnalysis
|
||||
* @version 1.1.3
|
||||
*/
|
||||
class ezcImageAnalyzerData extends ezcBaseStruct
|
||||
{
|
||||
/**
|
||||
* Detected MIME type for the image.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $mime;
|
||||
|
||||
/**
|
||||
* EXIF information retrieved from image.
|
||||
*
|
||||
* This will only be filled in for images which supports EXIF entries,
|
||||
* currently they are:
|
||||
* - image/jpeg
|
||||
* - image/tiff
|
||||
*
|
||||
* @link http://php.net/manual/en/function.exif-read-data.php
|
||||
*
|
||||
* @var array(string=>string)
|
||||
*/
|
||||
public $exif = array();
|
||||
|
||||
/**
|
||||
* Width of image in pixels.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $width = 0;
|
||||
|
||||
/**
|
||||
* Height of image in pixels.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $height = 0;
|
||||
|
||||
/**
|
||||
* Size of image file in bytes.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $size = 0;
|
||||
|
||||
/**
|
||||
* The image mode.
|
||||
*
|
||||
* Can be one of:
|
||||
* - ezcImageAnalyzerHandler::MODE_INDEXED - Image is built with a palette and consists of
|
||||
* indexed values per pixel.
|
||||
* - ezcImageAnalyzerHandler::MODE_TRUECOLOR - Image consists of RGB value per pixel.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $mode = ezcImageAnalyzerHandler::MODE_TRUECOLOR;
|
||||
|
||||
/**
|
||||
* Type of transparency in image.
|
||||
*
|
||||
* Can be one of:
|
||||
* - ezcImageAnalyzerHandler::TRANSPARENCY_OPAQUE - No parts of image is transparent.
|
||||
* - ezcImageAnalyzerHandler::TRANSPARENCY_TRANSPARENT - Selected palette entries are
|
||||
* completely see-through.
|
||||
* - ezcImageAnalyzerHandler::TRANSPARENCY_TRANSLUCENT - Transparency determined pixel per
|
||||
* pixel with a fuzzy value.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $transparencyType;
|
||||
|
||||
/**
|
||||
* Does the image have colors?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $isColor = true;
|
||||
|
||||
/**
|
||||
* Number of colors in image.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $colorCount = 0;
|
||||
|
||||
/**
|
||||
* First inline comment for the image.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $comment = null;
|
||||
|
||||
/**
|
||||
* List of inline comments for the image.
|
||||
*
|
||||
* @var array(string)
|
||||
*/
|
||||
public $commentList = array();
|
||||
|
||||
/**
|
||||
* Copyright text for the image.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $copyright = null;
|
||||
|
||||
/**
|
||||
* The date when the picture was taken as UNIX timestamp.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $date;
|
||||
|
||||
/**
|
||||
* Does the image have a thumbnail?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $hasThumbnail = false;
|
||||
|
||||
/**
|
||||
* Is the image animated?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $isAnimated = false;
|
||||
|
||||
/**
|
||||
* Create a new instance of ezcImageAnalyzerData.
|
||||
*
|
||||
* Create a new instance of ezcImageAnalyzerData to be used with
|
||||
* {@link ezcImageAnalyzer} objects.
|
||||
*
|
||||
* @see ezcImageAnalyzer::analyzeImage()
|
||||
* @see ezcImageAnalyzerHandler::analyzeImage()
|
||||
*
|
||||
* @param string $mime {@link ezcImageAnalyzerData::$mime}
|
||||
* @param array $exif {@link ezcImageAnalyzerData::$exif}
|
||||
* @param int $width {@link ezcImageAnalyzerData::$width}
|
||||
* @param int $height {@link ezcImageAnalyzerData::$height}
|
||||
* @param int $size {@link ezcImageAnalyzerData::$size}
|
||||
* @param int $mode {@link ezcImageAnalyzerData::$mode}
|
||||
* @param int $transparencyType {@link ezcImageAnalyzerData::$transparencyType}
|
||||
* @param bool $isColor {@link ezcImageAnalyzerData::$isColor}
|
||||
* @param int $colorCount {@link ezcImageAnalyzerData::$colorCount}
|
||||
* @param string $comment {@link ezcImageAnalyzerData::$comment}
|
||||
* @param array $commentList {@link ezcImageAnalyzerData::$commentList}
|
||||
* @param string $copyright {@link ezcImageAnalyzerData::$copyright}
|
||||
* @param int $date {@link ezcImageAnalyzerData::$date}
|
||||
* @param bool $hasThumbnail {@link ezcImageAnalyzerData::$hasThumbnail}
|
||||
* @param bool $isAnimated {@link ezcImageAnalyzerData::$isAnimated}
|
||||
*/
|
||||
public function __construct(
|
||||
$mime = null,
|
||||
$exif = array(),
|
||||
$width = 0,
|
||||
$height = 0,
|
||||
$size = 0,
|
||||
$mode = ezcImageAnalyzerHandler::MODE_TRUECOLOR,
|
||||
$transparencyType = null,
|
||||
$isColor = true,
|
||||
$colorCount = 0,
|
||||
$comment = null,
|
||||
$commentList = array(),
|
||||
$copyright = null,
|
||||
$date = null,
|
||||
$hasThumbnail = false,
|
||||
$isAnimated = false
|
||||
)
|
||||
{
|
||||
$this->mime = $mime;
|
||||
$this->exif = $exif;
|
||||
$this->width = $width;
|
||||
$this->height = $height;
|
||||
$this->size = $size;
|
||||
$this->mode = $mode;
|
||||
$this->transparencyType = $transparencyType;
|
||||
$this->isColor = $isColor;
|
||||
$this->colorCount = $colorCount;
|
||||
$this->comment = $comment;
|
||||
$this->commentList = $commentList;
|
||||
$this->copyright = $copyright;
|
||||
$this->date = $date;
|
||||
$this->hasThumbnail = $hasThumbnail;
|
||||
$this->isAnimated = $isAnimated;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,818 @@
|
||||
<?php
|
||||
/**
|
||||
* ezcConsoleToolsOutputTest
|
||||
*
|
||||
* @package ImageAnalysis
|
||||
* @version 1.1.3
|
||||
* @subpackage Tests
|
||||
* @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test suite for ImageAnalyzer class.
|
||||
*
|
||||
* @package ImageAnalysis
|
||||
* @subpackage Tests
|
||||
*/
|
||||
class ezcImageAnalysisAnalyzerTest extends ezcTestCase
|
||||
{
|
||||
|
||||
protected $basePath;
|
||||
|
||||
protected $testFiles = array(
|
||||
'exif_jpeg' => 'jpeg_exif.jpg',
|
||||
'noexif_jpeg' => 'jpeg_noexif.jpg',
|
||||
'exif_tiff' => 'tiff_exif.tiff',
|
||||
'noexif_tiff' => 'tiff_noexif.tiff',
|
||||
'animated_gif' => 'gif_animated.gif',
|
||||
'noanimated_gif' => 'gif_nonanimated.gif',
|
||||
'noanimated_png' => 'png_nonanimated.png',
|
||||
'svg' => 'svg.svg',
|
||||
);
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
return new PHPUnit_Framework_TestSuite( "ezcImageAnalysisAnalyzerTest" );
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if ( !ezcBaseFeatures::hasExtensionSupport( 'exif' ) )
|
||||
{
|
||||
$this->markTestSkipped( 'ext/exif is required to run this test.' );
|
||||
}
|
||||
|
||||
$this->basePath = dirname( __FILE__ ) . '/data/';
|
||||
}
|
||||
|
||||
public function testPhpHandlerGetMimeJpegExif()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['exif_jpeg'];
|
||||
$analyzer = $this->getAnalyzerPhpHandler( $file );
|
||||
$this->assertSame(
|
||||
'image/jpeg',
|
||||
$analyzer->mime,
|
||||
'MIME-Type was not determined correctly for JPEG.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testImagemagickHandlerGetMimeJpegExif()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['exif_jpeg'];
|
||||
$analyzer = $this->getAnalyzerImagemagickHandler( $file );
|
||||
$this->assertSame(
|
||||
'image/jpeg',
|
||||
$analyzer->mime,
|
||||
'MIME-Type was not determined correctly for JPEG.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testPhpHandlerGetMimeJpegNoexif()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['noexif_jpeg'];
|
||||
$analyzer = $this->getAnalyzerPhpHandler( $file );
|
||||
$this->assertSame(
|
||||
'image/jpeg',
|
||||
$analyzer->mime,
|
||||
'MIME-Type was not determined correctly for JPEG.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testImagemagickHandlerGetMimeJpegNoexif()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['noexif_jpeg'];
|
||||
$analyzer = $this->getAnalyzerImagemagickHandler( $file );
|
||||
$this->assertSame(
|
||||
'image/jpeg',
|
||||
$analyzer->mime,
|
||||
'MIME-Type was not determined correctly for JPEG.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testPhpHandlerGetMimeTiffExif()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['exif_tiff'];
|
||||
$analyzer = $this->getAnalyzerPhpHandler( $file );
|
||||
$this->assertSame(
|
||||
'image/tiff',
|
||||
$analyzer->mime,
|
||||
'MIME-Type was not determined correctly for TIFF.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testImagemagickHandlerGetMimeTiffExif()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['exif_tiff'];
|
||||
$analyzer = $this->getAnalyzerImagemagickHandler( $file );
|
||||
$this->assertSame(
|
||||
'image/tiff',
|
||||
$analyzer->mime,
|
||||
'MIME-Type was not determined correctly for TIFF.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testPhpHandlerGetMimeTiffNoexif()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['noexif_tiff'];
|
||||
$analyzer = $this->getAnalyzerPhpHandler( $file );
|
||||
$this->assertSame(
|
||||
'image/tiff',
|
||||
$analyzer->mime,
|
||||
'MIME-Type was not determined correctly for TIFF.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testImagemagickHandlerGetMimeTiffNoexif()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['noexif_tiff'];
|
||||
$analyzer = $this->getAnalyzerImagemagickHandler( $file );
|
||||
$this->assertSame(
|
||||
'image/tiff',
|
||||
$analyzer->mime,
|
||||
'MIME-Type was not determined correctly for TIFF.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testPhpHandlerGetMimeGifNonanimated()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['noanimated_gif'];
|
||||
$analyzer = $this->getAnalyzerPhpHandler( $file );
|
||||
$this->assertSame(
|
||||
'image/gif',
|
||||
$analyzer->mime,
|
||||
'MIME-Type was not determined correctly for GIF.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testImagemagickHandlerGetMimeGifNonanimated()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['noanimated_gif'];
|
||||
$analyzer = $this->getAnalyzerImagemagickHandler( $file );
|
||||
$this->assertSame(
|
||||
'image/gif',
|
||||
$analyzer->mime,
|
||||
'MIME-Type was not determined correctly for GIF.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testPhpHandlerGetMimeGifAnimated()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['animated_gif'];
|
||||
$analyzer = $this->getAnalyzerPhpHandler( $file );
|
||||
$this->assertSame(
|
||||
'image/gif',
|
||||
$analyzer->mime,
|
||||
'MIME-Type was not determined correctly for GIF.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testImagemagickHandlerGetMimeGifAnimated()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['animated_gif'];
|
||||
$analyzer = $this->getAnalyzerImagemagickHandler( $file );
|
||||
$this->assertSame(
|
||||
'image/gif',
|
||||
$analyzer->mime,
|
||||
'MIME-Type was not determined correctly for GIF.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testPhpHandlerGetMimePngNonanimated()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['noanimated_png'];
|
||||
$analyzer = $this->getAnalyzerPhpHandler( $file );
|
||||
$this->assertSame(
|
||||
'image/png',
|
||||
$analyzer->mime,
|
||||
'MIME-Type was not determined correctly for PNG.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testImagemagickHandlerGetMimePngNonanimated()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['noanimated_png'];
|
||||
$analyzer = $this->getAnalyzerImagemagickHandler( $file );
|
||||
$this->assertSame(
|
||||
'image/png',
|
||||
$analyzer->mime,
|
||||
'MIME-Type was not determined correctly for PNG.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testPhpHandlerJpegExifReportsDetails()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['exif_jpeg'];
|
||||
$analyzer = $this->getAnalyzerPhpHandler( $file );
|
||||
$this->assertSame(
|
||||
399,
|
||||
$analyzer->data->width,
|
||||
'<width> not extracted correctly for JPEG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
600,
|
||||
$analyzer->data->height,
|
||||
'<height> not extracted correctly for JPEG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
true,
|
||||
$analyzer->data->isColor,
|
||||
'<isColor> not extracted correctly for JPEG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
' ',
|
||||
$analyzer->data->comment,
|
||||
'<comment> not extracted correctly for JPEG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
76383,
|
||||
$analyzer->data->size,
|
||||
'<size> not extracted correctly for JPEG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
false,
|
||||
$analyzer->data->isAnimated,
|
||||
'<isAnimated> not extracted correctly for JPEG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
true,
|
||||
$analyzer->data->hasThumbnail,
|
||||
'<hasThumbnail> not extracted correctly for JPEG.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testImagemagickHandlerJpegExifReportsDetails()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['exif_jpeg'];
|
||||
$analyzer = $this->getAnalyzerImagemagickHandler( $file );
|
||||
$this->assertSame(
|
||||
399,
|
||||
$analyzer->data->width,
|
||||
'<width> not extracted correctly for JPEG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
600,
|
||||
$analyzer->data->height,
|
||||
'<height> not extracted correctly for JPEG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
true,
|
||||
$analyzer->data->isColor,
|
||||
'<isColor> not extracted correctly for JPEG.'
|
||||
);
|
||||
// @FIXME: update test case, as soon as Exif works here.
|
||||
$this->assertSame(
|
||||
null,
|
||||
$analyzer->data->comment,
|
||||
'<comment> not extracted correctly for JPEG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
76383,
|
||||
$analyzer->data->size,
|
||||
'<size> not extracted correctly for JPEG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
false,
|
||||
$analyzer->data->isAnimated,
|
||||
'<isAnimated> not extracted correctly for JPEG.'
|
||||
);
|
||||
// @FIXME: update test case, as soon as Exif works here.
|
||||
/*
|
||||
$this->assertSame(
|
||||
true,
|
||||
$analyzer->data->hasThumbnail,
|
||||
'<hasThumbnail> not extracted correctly for JPEG.'
|
||||
);
|
||||
*/
|
||||
}
|
||||
|
||||
public function testPhpHandlerJpegNoexifReportsDetails()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['noexif_jpeg'];
|
||||
$analyzer = $this->getAnalyzerPhpHandler( $file );
|
||||
$this->assertSame(
|
||||
399,
|
||||
$analyzer->data->width,
|
||||
'<width> not extracted correctly for JPEG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
600,
|
||||
$analyzer->data->height,
|
||||
'<height> not extracted correctly for JPEG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
true,
|
||||
$analyzer->data->isColor,
|
||||
'<isColor> not extracted correctly for JPEG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
null,
|
||||
$analyzer->data->comment,
|
||||
'<comment> not extracted correctly for JPEG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
68802,
|
||||
$analyzer->data->size,
|
||||
'<size> not extracted correctly for JPEG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
false,
|
||||
$analyzer->data->isAnimated,
|
||||
'<isAnimated> not extracted correctly for JPEG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
false,
|
||||
$analyzer->data->hasThumbnail,
|
||||
'<hasThumbnail> not extracted correctly for JPEG.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testImagemagickHandlerJpegNoexifReportsDetails()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['noexif_jpeg'];
|
||||
$analyzer = $this->getAnalyzerImagemagickHandler( $file );
|
||||
$this->assertSame(
|
||||
399,
|
||||
$analyzer->data->width,
|
||||
'<width> not extracted correctly for JPEG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
600,
|
||||
$analyzer->data->height,
|
||||
'<height> not extracted correctly for JPEG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
true,
|
||||
$analyzer->data->isColor,
|
||||
'<isColor> not extracted correctly for JPEG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
null,
|
||||
$analyzer->data->comment,
|
||||
'<comment> not extracted correctly for JPEG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
68802,
|
||||
$analyzer->data->size,
|
||||
'<size> not extracted correctly for JPEG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
false,
|
||||
$analyzer->data->isAnimated,
|
||||
'<isAnimated> not extracted correctly for JPEG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
false,
|
||||
$analyzer->data->hasThumbnail,
|
||||
'<hasThumbnail> not extracted correctly for JPEG.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testPhpHandlerTiffExifReportsDetails()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['exif_tiff'];
|
||||
$analyzer = $this->getAnalyzerPhpHandler( $file );
|
||||
$this->assertSame(
|
||||
399,
|
||||
$analyzer->data->width,
|
||||
'<width> not extracted correctly for TIFF.'
|
||||
);
|
||||
$this->assertSame(
|
||||
600,
|
||||
$analyzer->data->height,
|
||||
'<height> not extracted correctly for TIFF.'
|
||||
);
|
||||
$this->assertSame(
|
||||
true,
|
||||
$analyzer->data->isColor,
|
||||
'<isColor> not extracted correctly for TIFF.'
|
||||
);
|
||||
$this->assertSame(
|
||||
null,
|
||||
$analyzer->data->comment,
|
||||
'<comment> not extracted correctly for TIFF.'
|
||||
);
|
||||
$this->assertSame(
|
||||
108125,
|
||||
$analyzer->data->size,
|
||||
'<size> not extracted correctly for TIFF.'
|
||||
);
|
||||
$this->assertSame(
|
||||
false,
|
||||
$analyzer->data->isAnimated,
|
||||
'<isAnimated> not extracted correctly for TIFF.'
|
||||
);
|
||||
$this->assertSame(
|
||||
false,
|
||||
$analyzer->data->hasThumbnail,
|
||||
'<hasThumbnail> not extracted correctly for TIFF.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testImagemagickHandlerTiffExifReportsDetails()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['exif_tiff'];
|
||||
$analyzer = $this->getAnalyzerImagemagickHandler( $file );
|
||||
$this->assertSame(
|
||||
399,
|
||||
$analyzer->data->width,
|
||||
'<width> not extracted correctly for TIFF.'
|
||||
);
|
||||
$this->assertSame(
|
||||
600,
|
||||
$analyzer->data->height,
|
||||
'<height> not extracted correctly for TIFF.'
|
||||
);
|
||||
$this->assertSame(
|
||||
true,
|
||||
$analyzer->data->isColor,
|
||||
'<isColor> not extracted correctly for TIFF.'
|
||||
);
|
||||
// FIXME: Exif does not show comment, but ImageMagick does!!!
|
||||
$this->assertSame(
|
||||
'A simple comment in a TIFF file.',
|
||||
$analyzer->data->comment,
|
||||
'<comment> not extracted correctly for TIFF.'
|
||||
);
|
||||
$this->assertSame(
|
||||
108125,
|
||||
$analyzer->data->size,
|
||||
'<size> not extracted correctly for TIFF.'
|
||||
);
|
||||
$this->assertSame(
|
||||
false,
|
||||
$analyzer->data->isAnimated,
|
||||
'<isAnimated> not extracted correctly for TIFF.'
|
||||
);
|
||||
$this->assertSame(
|
||||
false,
|
||||
$analyzer->data->hasThumbnail,
|
||||
'<hasThumbnail> not extracted correctly for TIFF.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testPhpHandlerTiffNoexifReportsDetails()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['noexif_tiff'];
|
||||
$analyzer = $this->getAnalyzerPhpHandler( $file );
|
||||
$this->assertSame(
|
||||
399,
|
||||
$analyzer->data->width,
|
||||
'<width> not extracted correctly for TIFF.'
|
||||
);
|
||||
$this->assertSame(
|
||||
600,
|
||||
$analyzer->data->height,
|
||||
'<height> not extracted correctly for TIFF.'
|
||||
);
|
||||
$this->assertSame(
|
||||
true,
|
||||
$analyzer->data->isColor,
|
||||
'<isColor> not extracted correctly for TIFF.'
|
||||
);
|
||||
$this->assertSame(
|
||||
null,
|
||||
$analyzer->data->comment,
|
||||
'<comment> not extracted correctly for TIFF.'
|
||||
);
|
||||
$this->assertSame(
|
||||
108043,
|
||||
$analyzer->data->size,
|
||||
'<size> not extracted correctly for TIFF.'
|
||||
);
|
||||
$this->assertSame(
|
||||
false,
|
||||
$analyzer->data->isAnimated,
|
||||
'<isAnimated> not extracted correctly for TIFF.'
|
||||
);
|
||||
$this->assertSame(
|
||||
false,
|
||||
$analyzer->data->hasThumbnail,
|
||||
'<hasThumbnail> not extracted correctly for TIFF.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testImagemagickHandlerTiffNoexifReportsDetails()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['noexif_tiff'];
|
||||
$analyzer = $this->getAnalyzerImagemagickHandler( $file );
|
||||
$this->assertSame(
|
||||
399,
|
||||
$analyzer->data->width,
|
||||
'<width> not extracted correctly for TIFF.'
|
||||
);
|
||||
$this->assertSame(
|
||||
600,
|
||||
$analyzer->data->height,
|
||||
'<height> not extracted correctly for TIFF.'
|
||||
);
|
||||
$this->assertSame(
|
||||
true,
|
||||
$analyzer->data->isColor,
|
||||
'<isColor> not extracted correctly for TIFF.'
|
||||
);
|
||||
$this->assertSame(
|
||||
null,
|
||||
$analyzer->data->comment,
|
||||
'<comment> not extracted correctly for TIFF.'
|
||||
);
|
||||
$this->assertSame(
|
||||
108043,
|
||||
$analyzer->data->size,
|
||||
'<size> not extracted correctly for TIFF.'
|
||||
);
|
||||
$this->assertSame(
|
||||
false,
|
||||
$analyzer->data->isAnimated,
|
||||
'<isAnimated> not extracted correctly for TIFF.'
|
||||
);
|
||||
$this->assertSame(
|
||||
false,
|
||||
$analyzer->data->hasThumbnail,
|
||||
'<hasThumbnail> not extracted correctly for TIFF.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testPhpHandlerPngReportsDetails()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['noanimated_png'];
|
||||
$analyzer = $this->getAnalyzerPhpHandler( $file );
|
||||
$this->assertSame(
|
||||
160,
|
||||
$analyzer->data->width,
|
||||
'<width> not extracted correctly for PNG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
120,
|
||||
$analyzer->data->height,
|
||||
'<height> not extracted correctly for PNG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
5420,
|
||||
$analyzer->data->size,
|
||||
'<size> not extracted correctly for PNG.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testImagemagickHandlerPngReportsDetails()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['noanimated_png'];
|
||||
$analyzer = $this->getAnalyzerImagemagickHandler( $file );
|
||||
$this->assertSame(
|
||||
160,
|
||||
$analyzer->data->width,
|
||||
'<width> not extracted correctly for PNG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
120,
|
||||
$analyzer->data->height,
|
||||
'<height> not extracted correctly for PNG.'
|
||||
);
|
||||
$this->assertSame(
|
||||
5420,
|
||||
$analyzer->data->size,
|
||||
'<size> not extracted correctly for PNG.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testPhpHandlerAnimatedGifReportsAnimated()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['animated_gif'];
|
||||
$analyzer = $this->getAnalyzerPhpHandler( $file );
|
||||
$this->assertSame(
|
||||
true,
|
||||
$analyzer->data->isAnimated,
|
||||
'<isAnimated> not extracted correctly for GIF.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testImagemagickHandlerAnimatedGifReportsAnimated()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['animated_gif'];
|
||||
$analyzer = $this->getAnalyzerImagemagickHandler( $file );
|
||||
$this->assertSame(
|
||||
true,
|
||||
$analyzer->data->isAnimated,
|
||||
'<isAnimated> not extracted correctly for GIF.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testPhpHandlerNoexifJpegReportsNotAnimated()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['noexif_jpeg'];
|
||||
$analyzer = $this->getAnalyzerPhpHandler( $file );
|
||||
$this->assertSame(
|
||||
false,
|
||||
$analyzer->data->isAnimated,
|
||||
'<isAnimated> no extracted correctly for JPEG.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testImagemagickHandlerNoexifJpegReportsNotAnimated()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['noexif_jpeg'];
|
||||
$analyzer = $this->getAnalyzerImagemagickHandler( $file );
|
||||
$this->assertSame(
|
||||
false,
|
||||
$analyzer->data->isAnimated,
|
||||
'<isAnimated> no extracted correctly for JPEG.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testPhpHandlerNonanimatedGifReportsNotAnimated()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['noanimated_gif'];
|
||||
$analyzer = $this->getAnalyzerPhpHandler( $file );
|
||||
$this->assertSame(
|
||||
false,
|
||||
$analyzer->data->isAnimated,
|
||||
'<isAnimated> not extracted correctly for GIF.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testImagemagickHandlerNonanimatedGifReportsNotAnimated()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['noanimated_gif'];
|
||||
$analyzer = $this->getAnalyzerImagemagickHandler( $file );
|
||||
$this->assertSame(
|
||||
false,
|
||||
$analyzer->data->isAnimated,
|
||||
'<isAnimated> not extracted correctly for GIF.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testPhpHandlerExifJpegReportsNotAnimated()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['exif_jpeg'];
|
||||
|
||||
// Test Php handler
|
||||
$analyzer = $this->getAnalyzerPhpHandler( $file );
|
||||
$this->assertSame(
|
||||
false,
|
||||
$analyzer->data->isAnimated,
|
||||
'<isAnimated> not extracted correctly for JPEG.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testImagemagickHandlerExifJpegReportsNotAnimated()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['exif_jpeg'];
|
||||
|
||||
// Test ImageMagick handler
|
||||
$analyzer = $this->getAnalyzerImageMagickHandler( $file );
|
||||
$this->assertSame(
|
||||
false,
|
||||
$analyzer->data->isAnimated,
|
||||
'<isAnimated> not extracted correctly for JPEG.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testSvgMimeType()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['svg'];
|
||||
$analyzer = $this->getAnalyzerImageMagickHandler( $file );
|
||||
$this->assertEquals(
|
||||
"image/svg+xml",
|
||||
$analyzer->mime,
|
||||
'<mime> not extracted correctly for SVG.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testAnalyzerGeneralNotProcessable()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected function getAnalyzerPhpHandler( $file )
|
||||
{
|
||||
ezcImageAnalyzer::setHandlerClasses( array( 'ezcImageAnalyzerPhpHandler' => array() ) );
|
||||
return new ezcImageAnalyzer( $file );
|
||||
}
|
||||
|
||||
protected function getAnalyzerImageMagickHandler( $file )
|
||||
{
|
||||
ezcImageAnalyzer::setHandlerClasses( array( 'ezcImageAnalyzerImagemagickHandler' => array() ) );
|
||||
return new ezcImageAnalyzer( $file );
|
||||
}
|
||||
|
||||
public function testPropertiesGetInvalid()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['svg'];
|
||||
$analyzer = $this->getAnalyzerImageMagickHandler( $file );
|
||||
try
|
||||
{
|
||||
$analyzer->no_such_property;
|
||||
$this->fail( 'Expected exception was not thrown.' );
|
||||
}
|
||||
catch ( ezcBasePropertyNotFoundException $e )
|
||||
{
|
||||
$expected = "No such property name 'no_such_property'.";
|
||||
$this->assertEquals( $expected, $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testPropertiesSetDenied()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['svg'];
|
||||
$analyzer = $this->getAnalyzerImageMagickHandler( $file );
|
||||
try
|
||||
{
|
||||
$analyzer->mime = 'some value';
|
||||
$this->fail( 'Expected exception was not thrown.' );
|
||||
}
|
||||
catch ( ezcBasePropertyPermissionException $e )
|
||||
{
|
||||
$expected = "The property 'mime' is read-only.";
|
||||
$this->assertEquals( $expected, $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testPropertiesSetInvalid()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['svg'];
|
||||
$analyzer = $this->getAnalyzerImageMagickHandler( $file );
|
||||
try
|
||||
{
|
||||
$analyzer->no_such_property = 'some value';
|
||||
$this->fail( 'Expected exception was not thrown.' );
|
||||
}
|
||||
catch ( ezcBasePropertyNotFoundException $e )
|
||||
{
|
||||
$expected = "No such property name 'no_such_property'.";
|
||||
$this->assertEquals( $expected, $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testImagemagickHandlerNonExistentFile()
|
||||
{
|
||||
$fileName = $this->basePath . "no_such_file.svg";
|
||||
try
|
||||
{
|
||||
$analyzer = $this->getAnalyzerImageMagickHandler( $fileName );
|
||||
$this->fail( 'Expected exception was not thrown' );
|
||||
}
|
||||
catch ( ezcBaseFileNotFoundException $e )
|
||||
{
|
||||
$expected = "The file '{$fileName}' could not be found.";
|
||||
$this->assertEquals( $expected, $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testImagemagickHandlerUnreadableFile()
|
||||
{
|
||||
$tempDir = $this->createTempDir( 'ezcImageAnalysisAnalyzerTest' );
|
||||
$fileName = $tempDir . "/test-unreadable.svg";
|
||||
$fileHandle = fopen( $fileName, "wb" );
|
||||
fwrite( $fileHandle, "some contents" );
|
||||
fclose( $fileHandle );
|
||||
chmod( $fileName, 0 );
|
||||
|
||||
try
|
||||
{
|
||||
$analyzer = $this->getAnalyzerImageMagickHandler( $fileName );
|
||||
$this->fail( 'Expected exception was not thrown' );
|
||||
}
|
||||
catch ( ezcBaseFilePermissionException $e )
|
||||
{
|
||||
$this->removeTempDir();
|
||||
$expected = "The file '{$fileName}' can not be opened for reading.";
|
||||
$this->assertEquals( $expected, $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testImagemagickHandlerNotProcessableFile()
|
||||
{
|
||||
$tempDir = $this->createTempDir( 'ezcImageAnalysisAnalyzerTest' );
|
||||
$fileName = $tempDir . "/test-unreadable.svg";
|
||||
$fileHandle = fopen( $fileName, "wb" );
|
||||
fwrite( $fileHandle, "some contents" );
|
||||
fclose( $fileHandle );
|
||||
|
||||
try
|
||||
{
|
||||
$analyzer = $this->getAnalyzerImageMagickHandler( $fileName );
|
||||
$this->fail( 'Expected exception was not thrown' );
|
||||
}
|
||||
catch ( ezcImageAnalyzerFileNotProcessableException $e )
|
||||
{
|
||||
$this->removeTempDir();
|
||||
$expected = "Could not process file '{$fileName}'. Reason: Could not determine MIME type of file..";
|
||||
$this->assertEquals( $expected, $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetHandlerClasses()
|
||||
{
|
||||
ezcImageAnalyzer::getHandlerClasses();
|
||||
}
|
||||
|
||||
public function testIsSet()
|
||||
{
|
||||
$file = $this->basePath . $this->testFiles['svg'];
|
||||
$analyzer = $this->getAnalyzerImageMagickHandler( $file );
|
||||
$this->assertEquals( true, isset( $analyzer->mime ) );
|
||||
$this->assertEquals( true, isset( $analyzer->data ) );
|
||||
$this->assertEquals( false, isset( $analyzer->no_such_property ) );
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 5.7 KiB |
|
After Width: | Height: | Size: 75 KiB |
|
After Width: | Height: | Size: 67 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
@@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://web.resource.org/cc/"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="50"
|
||||
height="10"
|
||||
id="svg2"
|
||||
sodipodi:version="0.32"
|
||||
inkscape:version="0.44.1"
|
||||
version="1.0"
|
||||
sodipodi:docbase="/home/dotxp/dev/ez/ezcomponents/trunk/ImageConversion/tests/data/compare"
|
||||
sodipodi:docname="test.svg">
|
||||
<defs
|
||||
id="defs4" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
gridtolerance="10000"
|
||||
guidetolerance="10"
|
||||
objecttolerance="10"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="15.607172"
|
||||
inkscape:cx="22.203569"
|
||||
inkscape:cy="2.3158231"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer1"
|
||||
width="50px"
|
||||
height="10px"
|
||||
inkscape:window-width="1099"
|
||||
inkscape:window-height="874"
|
||||
inkscape:window-x="180"
|
||||
inkscape:window-y="179" />
|
||||
<metadata
|
||||
id="metadata7">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<path
|
||||
style="font-size:12px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
|
||||
d="M 11.562077,0.61122227 L 18.962467,0.61122227 L 18.962467,1.607316 L 15.856998,1.607316 L 15.856998,9.3592691 L 14.667545,9.3592691 L 14.667545,1.607316 L 11.562077,1.607316 L 11.562077,0.61122227 M 25.677311,5.8084879 L 25.677311,6.3358316 L 20.72028,6.3358316 C 20.767153,7.0780214 20.989809,7.6444271 21.388248,8.0350504 C 21.790589,8.4217701 22.349183,8.6151293 23.06403,8.6151285 C 23.478088,8.6151293 23.878478,8.5643481 24.265202,8.4627848 C 24.655821,8.3612233 25.042539,8.2088797 25.425358,8.0057535 L 25.425358,9.0252848 C 25.038633,9.1893474 24.642149,9.3143473 24.235905,9.4002848 C 23.82965,9.4862221 23.417541,9.5291908 22.999577,9.529191 C 21.952699,9.5291908 21.122621,9.2245037 20.509342,8.6151285 C 19.899966,8.0057549 19.595279,7.1815369 19.59528,6.1424723 C 19.595279,5.0682578 19.884341,4.2166962 20.462467,3.5877848 C 21.044496,2.9549787 21.827699,2.6385727 22.812077,2.638566 C 23.694884,2.6385727 24.392149,2.9237287 24.903873,3.4940348 C 25.419492,4.0604463 25.677304,4.8319299 25.677311,5.8084879 M 24.599186,5.4920816 C 24.591368,4.9022423 24.425352,4.4315397 24.101139,4.0799723 C 23.780822,3.7284154 23.355041,3.5526343 22.823795,3.5526285 C 22.22223,3.5526343 21.739808,3.722556 21.37653,4.0623941 C 21.017153,4.4022428 20.810122,4.880758 20.755436,5.497941 L 24.599186,5.4920816 M 31.630436,2.9901285 L 31.630436,4.0096598 C 31.325743,3.8534153 31.009338,3.7362279 30.681217,3.6580973 C 30.353088,3.579978 30.013245,3.5409156 29.661686,3.5409098 C 29.126527,3.5409156 28.724184,3.6229468 28.454655,3.7870035 C 28.189028,3.9510714 28.056215,4.1971649 28.056217,4.5252848 C 28.056215,4.7752894 28.151918,4.9725548 28.343327,5.1170816 C 28.534731,5.2577107 28.919496,5.3924762 29.497623,5.5213785 L 29.866764,5.6034098 C 30.632385,5.7674759 31.175353,5.9998975 31.49567,6.3006754 C 31.819884,6.5975532 31.981993,7.0135684 31.981998,7.5487223 C 31.981993,8.1580985 31.739806,8.6405199 31.255436,8.9959879 C 30.774963,9.3514566 30.112854,9.5291908 29.269108,9.529191 C 28.917543,9.5291908 28.550356,9.4940346 28.167545,9.4237223 C 27.788638,9.357316 27.388247,9.2557536 26.966373,9.1190348 L 26.966373,8.0057535 C 27.36481,8.2127859 27.757388,8.3690358 28.144108,8.4745035 C 28.530824,8.5760668 28.913636,8.626848 29.292545,8.6268473 C 29.800354,8.626848 30.190979,8.5409106 30.46442,8.3690348 C 30.737853,8.1932547 30.874572,7.9471612 30.874577,7.6307535 C 30.874572,7.3377868 30.774963,7.1131776 30.575748,6.9569254 C 30.380432,6.800678 29.948792,6.6502875 29.280827,6.5057535 L 28.905827,6.4178629 C 28.237856,6.277241 27.755435,6.0623974 27.458561,5.7733316 C 27.161685,5.4803668 27.013248,5.0799765 27.013248,4.5721598 C 27.013248,3.9549777 27.231998,3.4784156 27.669498,3.1424723 C 28.106997,2.8065413 28.72809,2.6385727 29.53278,2.638566 C 29.931214,2.6385727 30.306213,2.6678696 30.65778,2.7264566 C 31.009338,2.785057 31.333556,2.8729475 31.630436,2.9901285 M 34.771061,0.93348789 L 34.771061,2.7967691 L 36.991764,2.7967691 L 36.991764,3.6346598 L 34.771061,3.6346598 L 34.771061,7.1971598 C 34.771059,7.7323176 34.843324,8.0760673 34.987858,8.2284098 C 35.136293,8.3807545 35.435121,8.4569263 35.884342,8.4569254 L 36.991764,8.4569254 L 36.991764,9.3592691 L 35.884342,9.3592691 C 35.052308,9.3592691 34.47809,9.2049724 34.161686,8.8963785 C 33.845278,8.5838793 33.687075,8.0174736 33.687077,7.1971598 L 33.687077,3.6346598 L 32.896061,3.6346598 L 32.896061,2.7967691 L 33.687077,2.7967691 L 33.687077,0.93348789 L 34.771061,0.93348789"
|
||||
id="text1872" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 5.3 KiB |
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* ezcImageAnalysisSuite
|
||||
*
|
||||
* @package ImageAnalysis
|
||||
* @subpackage Tests
|
||||
* @version 1.1.3
|
||||
* @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
|
||||
* @license LGPL {@link http://www.gnu.org/copyleft/lesser.html}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Require test suite for ImageAnalyzer class.
|
||||
*/
|
||||
require_once 'analyzer_test.php';
|
||||
|
||||
/**
|
||||
* Test suite for ImageAnalysis package.
|
||||
*
|
||||
* @package ImageAnalysis
|
||||
* @subpackage Tests
|
||||
*/
|
||||
class ezcImageAnalysisSuite extends PHPUnit_Framework_TestSuite
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->setName( "ImageAnalysis" );
|
||||
$this->addTest( ezcImageAnalysisAnalyzerTest::suite() );
|
||||
}
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
return new ezcImageAnalysisSuite( "ezcImageAnalysisSuite" );
|
||||
}
|
||||
}
|
||||
?>
|
||||