Author: Tobias Schlitt Date: 2006-01-27 17:27:24 +0100 (Fri, 27 Jan 2006) New Revision: 2070
Log: - Adding tutorial. # Please review. Added: packages/ImageAnalysis/trunk/docs/tutorial.txt packages/ImageAnalysis/trunk/docs/tutorial_autoload.php packages/ImageAnalysis/trunk/docs/tutorial_example_01.php packages/ImageAnalysis/trunk/docs/tutorial_example_02.php packages/ImageAnalysis/trunk/docs/tutorial_example_03.php Added: packages/ImageAnalysis/trunk/docs/tutorial.txt =================================================================== --- packages/ImageAnalysis/trunk/docs/tutorial.txt 2006-01-27 15:49:43 UTC (rev 2069) +++ packages/ImageAnalysis/trunk/docs/tutorial.txt 2006-01-27 16:27:24 UTC (rev 2070) @@ -0,0 +1,142 @@ +eZ components - ImageAnalysis +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. contents:: Table of Contents + +Introduction +============ + +The ImageAnalysis component provides facilities to analyze certain attributes +of an image. + +Class overview +============== + +This section gives you an overview on all classes, that are intended to be +used directly. + +ezcImageAnalyzer + The main class of this package, it is responsible to handle the analysis of + image files, as well as caching the results for you. + +Installation +============ + +This tutorial assumes that you have set-up an eZ components environment. For +information on how to do this, please refer to the `Components Introduction`_. + +.. _`Components Introduction`: http://ez.no/community/articles/an_introduction_to_ez_components + + +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 7 a new ezcImageAnalyzer object is instantiated. This must be done for +each image to analyse. In line 9 you see how to access the MIME type determined +from the image. 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 +----------------------- + +Beside the MIME type, ImageAnalysis extracts more information, if you request it. +The following example shows how this works: + +.. include:: tutorial_example_01.php + :literal: + +The example is basically the same as no. 1, except that more data is requested +from ezcImageAnalyzer (lines 13-17). The major difference here is, that in +example 1, ezcImageAnalyzer has only determined the MIME type of the file and +has not performed any further analyzation. The analyzation of additional data +is performed on the first request to it (line 13). After that, the data is +cached in the ezcImageAnalyzer object. + +The width, height and size values are available for every analyzable image, +while a comment must not necessarily be available. At least, every datum has +some sensible default value, if unavailable. + +The example image and the output printed 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 ezcImageConversion, ezcImageAnalyzer is based on handler classes, which +allow it to utilize different back-ends for image analyzation. Currently +implemented are: + +ezcImageAnalyzerHandlerPhp + This one uses PHP's getimagesize() function (which does not require the GD + extension!) and probably PHP's exif extension, if it is available. + +ezcImageAnalyzerHandlerImagemagick + Here `ImageMagick`_'s "identify" program is used. + +Both handlers are activated by default and are capable of determining if their +preconditions are fulfilled themselves. + +It may happen that one needs to configure a handler, for example on some +systems you want to assign the path to the ImageMagick_ "identify" binary, +because it's not available in the $PATH environment variable. The following +example shows how this is possible and what else is configurable for the +handlers: + +.. _ImageMagick: http://www.imagemagick.org/script/index.php + +.. include:: tutorial_example_01.php + :literal: + +Basically, the code is the same as from example 2, except that the +ezcImageAnalyzer is being configured to only use its ImageMagick handler and +not the PHP handler. Beside that, the location of the "identify" binary is set +explicitly. 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, Oktober 2005. + +More Information +================ + +For more information, see the ezcImageConverter API reference. + + +.. + Local Variables: + mode: rst + fill-column: 79 + End: + vim: et syn=rst tw=79 Property changes on: packages/ImageAnalysis/trunk/docs/tutorial.txt ___________________________________________________________________ Name: svn:eol-style + native Added: packages/ImageAnalysis/trunk/docs/tutorial_autoload.php =================================================================== --- packages/ImageAnalysis/trunk/docs/tutorial_autoload.php 2006-01-27 15:49:43 UTC (rev 2069) +++ packages/ImageAnalysis/trunk/docs/tutorial_autoload.php 2006-01-27 16:27:24 UTC (rev 2070) @@ -0,0 +1,17 @@ +<?php + +require_once 'Base/trunk/src/base.php'; + +/** + * Autoload ezc classes + * + * @param string $class_name + */ +function __autoload( $class_name ) +{ + if ( ezcBase::autoload( $class_name ) ) + { + return; + } +} +?> Property changes on: packages/ImageAnalysis/trunk/docs/tutorial_autoload.php ___________________________________________________________________ Name: svn:eol-style + native Added: packages/ImageAnalysis/trunk/docs/tutorial_example_01.php =================================================================== --- packages/ImageAnalysis/trunk/docs/tutorial_example_01.php 2006-01-27 15:49:43 UTC (rev 2069) +++ packages/ImageAnalysis/trunk/docs/tutorial_example_01.php 2006-01-27 16:27:24 UTC (rev 2070) @@ -0,0 +1,11 @@ +<?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"; + +?> Property changes on: packages/ImageAnalysis/trunk/docs/tutorial_example_01.php ___________________________________________________________________ Name: svn:eol-style + native Added: packages/ImageAnalysis/trunk/docs/tutorial_example_02.php =================================================================== --- packages/ImageAnalysis/trunk/docs/tutorial_example_02.php 2006-01-27 15:49:43 UTC (rev 2069) +++ packages/ImageAnalysis/trunk/docs/tutorial_example_02.php 2006-01-27 16:27:24 UTC (rev 2070) @@ -0,0 +1,21 @@ +<?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"; + +?> Property changes on: packages/ImageAnalysis/trunk/docs/tutorial_example_02.php ___________________________________________________________________ Name: svn:eol-style + native Added: packages/ImageAnalysis/trunk/docs/tutorial_example_03.php =================================================================== --- packages/ImageAnalysis/trunk/docs/tutorial_example_03.php 2006-01-27 15:49:43 UTC (rev 2069) +++ packages/ImageAnalysis/trunk/docs/tutorial_example_03.php 2006-01-27 16:27:24 UTC (rev 2070) @@ -0,0 +1,27 @@ +<?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"; + +?> Property changes on: packages/ImageAnalysis/trunk/docs/tutorial_example_03.php ___________________________________________________________________ Name: svn:eol-style + native -- svn-components mailing list [email protected] http://lists.ez.no/mailman/listinfo/svn-components
