eZImageManager Class Reference
[Image conversion and scaling]

Manages image operations using delegates to do the work. More...

List of all members.


Public Methods

 eZImageManager ()
 setOutputTypes ($mimes)
 setRules ($rules,$defrule)
 registerType ($name,&$type)
 ruleFor ($from)
 isDisplayType ($type)
createMIMEType ($mime,$match,$suffix)
 setMIMETypes ($types)
 mimeTypeFor ($file,$as_obj=false)
convertRules ($from,$scale=false)
 addScaleRule (&$rules,$scale)
 addFilterRule (&$rules,$filter)
 convert ($file,$dest,$scale=false,$filters=false,$mime=false)
createRule ($from,$to,$type,$scale,$filter)
instance ()

Private Methods

 compressRules (&$rules,$scale)

Detailed Description

Manages image operations using delegates to do the work.

The manager allows for transparent conversion of one image format to another. The conversion may be done in one step if the required conversion type is available or it may build a tree of conversion rules which is needed to reach the desired end format.

It's also possible to run operations on images. It's up to each conversion rule to report whether or not the operation is supported, the manager will then distribute the operations on the available rules which can handle them. Examples of operations are scaling and grayscale.

The scale operation is special and is known to the manager directly while the other operations must be recognized by the converter.

In determing what image rules to be used the manager must first know which output types are allowed, this is set with setOutputTypes(). It takes an array of mimetypes which are allowed.

The manager must then be fed conversion rules, these tell which conversion type is used for converting from the source mimetype to the destination mimetype. The rules are set with createRule() function, it takes the source and destination mimetype as well as the conversion type name. Optionally it can specified whether the rule can scale or run operations.

The last thing that needs to be done is to specify the mimetypes. The manager uses mimetypes internally to know what type of image it's working on. To go from a filename to a mimetype a set of matches must be setup. The matches are created with setMIMETypes().

See www.iana.org for information on MIME types.

Now the manager is ready and you can convert images with convert().

Example:

$img =& eZImageManager::instance();
$img->registerType( "convert", new eZImageShell( '', "convert", array(), array(),
                                                 array( eZImageShell::createRule( "-geometry %wx%h>", // Scale rule
                                                                                  "modify/scale" ),
                                                        eZImageShell::createRule( "-colorspace GRAY", // Grayscale rule
                                                                                  "colorspace/gray" ) ) ) ); // Register shell program convert
$img->registerType( "gd", new eZImageGD() ); // Register PHP converter GD

$img->setOutputTypes( array( "image/jpeg",
                             "image/png" ) ); // We only want jpeg and png, gif is not recommended due to licencing issues.
$rules = array( $img->createRule( "image/jpeg", "image/jpeg", "GD", true, false ), // Required for scaling jpeg images
                $img->createRule( "image/gif", "image/png", "convert", true, false ) ); // Convert GIF to png
$img->setRules( $rules, $img->createRule( "*", "image/png", "convert", true, false ) ); // Convert all other images to PNG with convert

$mime_rules = array( $img->createMIMEType( "image/jpeg", "\.jpe?g$", "jpg" ),
                     $img->createMIMEType( "image/png", "\.png$", "png" ),
                     $img->createMIMEType( "image/gif", "\.gif$", "gif" ) );
$img->setMIMETypes( $mime_rules ); // Register mimetypes

$img1 = $img->convert( "image1.gif", "cache/" ); // Convert GIF and places it in cache dir
$img1 = $img->convert( "image1.png", "cache/", // Scale PNG image and place in cache dir
                       array( "width" => 200, "height" => 200 ), // Scale parameter
                       array( array( "rule-type" => "colorspace/gray" ) ) ); // Gray scale conversion

Definition at line ezimagemanager.php.


Constructor & Destructor Documentation

eZImageManager::eZImageManager  
 

Initializes the manager by registering a application/octet-stream mimetype which is applied for all unknown files.

Definition at line ezimagemanager.php.

References createMIMEType().

Referenced by instance().


Member Function Documentation

eZImageManager::addFilterRule &$    rules,
  filter
 

Adds the filter rules $filter to the first rule which can perform filtering. $rules is usually the rules returned from convertRules().

Definition at line ezimagemanager.php.

Referenced by convert().

eZImageManager::addScaleRule &$    rules,
  scale
 

Adds the scale rule $scale to the first rule which can perform scaling. $rules is usually the rules returned from convertRules().

Definition at line ezimagemanager.php.

Referenced by convert().

eZImageManager::compressRules &$    rules,
  scale
[private]
 

Compresses the rules $rules so that a minimum number of conversion is required. The scale $rule is taken into account.

Definition at line ezimagemanager.php.

Referenced by convertRules().

eZImageManager::convert   file,
  dest,
  scale = false,
  filters = false,
  mime = false
 

Converst the image file $file to an output format and places it in $dest. Scaling is handled with $scale and filters with $filters. If $mime is false then the mimetype i fetched from the $file.

Definition at line ezimagemanager.php.

References mimeTypeFor().

& eZImageManager::convertRules   from,
  scale = false
 

Returns the conversion rules which is required for transforming the mimetype $from to an output format. If scale is supplied the scaling is taking into account when compressing rules.

Definition at line ezimagemanager.php.

References isDisplayType().

Referenced by convert().

& eZImageManager::createMIMEType   mime,
  match,
  suffix
 

Creates a MIME type structure. $mime is the mimetype name, $match is the regex file match, $suffix is the filename suffix which is append to the converted filename.

Definition at line ezimagemanager.php.

Referenced by eZImageManager().

& eZImageManager::createRule   from,
  to,
  type,
  scale,
  filter
 

Creates a new conversion rule and returns it. $from the source mimetype, $to the destination mimetype, $type the image conversion type must be registered, $scale true if the rule can scale the image, $filter true if the rule can perform filters.

Definition at line ezimagemanager.php.

& eZImageManager::instance  
 

Returns the only instance of the image manager.

Definition at line ezimagemanager.php.

References instance().

Referenced by instance().

eZImageManager::isDisplayType   type
 

Returns true if the mimetype $type is accepted as an output type.

Definition at line ezimagemanager.php.

Referenced by convertRules().

eZImageManager::mimeTypeFor   file,
  as_obj = false
 

Returns the mimetype for the file $file. If $as_obj is true the whole mimetype structure is returned.

Definition at line ezimagemanager.php.

Referenced by convert().

eZImageManager::registerType   name,
&$    type
 

Registers a new conversion type which can handle conversion and image operations. The name $name represents the conversion name which is used in the conversion rules. $type is the conversion object.

Definition at line ezimagemanager.php.

eZImageManager::ruleFor   from
 

Not used for now, may be deleted?

Definition at line ezimagemanager.php.

eZImageManager::setMIMETypes   types
 

Register the mimetypes $types.

Definition at line ezimagemanager.php.

eZImageManager::setOutputTypes   mimes
 

Sets which output types are allowed, this is an array of mimetype names.

Definition at line ezimagemanager.php.

eZImageManager::setRules   rules,
  defrule
 

Sets the conversion rules to $rule and the default rule to $defrule.

Definition at line ezimagemanager.php.


The documentation for this class was generated from the following file:  

Exponential