Path

ez components / documentation / api reference / latest / imageconversion


eZ Components latest

ImageConversion: ezcImageTransformation

[ Tutorial ] [ Class tree ] [ Element index ] [ ChangeLog ] [ Credits ]

Class: ezcImageTransformation

Provides transformations on images using filters and MIME conversions. [source]
Objects of this class group MIME type conversion and filtering of images into transformations of images. Transformations can be chained by referencing to another transformation so that multiple transformations will be produced after each other.
 1.  $filters array(
 2.    new ezcImageFilter'scaleDownByWidth',
 3.                         array(
 4.                             'width' => 100
 5.                         )
 6.        ),
 7.    new ezcImageFilter'crop',
 8.                         array(
 9.                             'x' => 0,
10.                             'y' => 0,
11.                             'width'  => 100,
12.                             'height' => 100,
13.                         )
14.        ),
15.  );
16.  $mimeTypes array'image/jpeg''image/png' );
17.  
18.  // ezcImageTransformation object returned for further manipulation
19.  $thumbnail $converter->createTransformation(
20.       'thumbnail',
21.       $filters,
22.       $mimeTypes
23.  );
24.  
25.  $converter->transform'thumbnail''var/storage/myOriginal1.jpg',
26.                         'var/storage/myThumbnail1' )// res: image/jpeg
27.  $converter->transform'thumbnail''var/storage/myOriginal2.png',
28.                         'var/storage/myThumbnail2' )// res: image/png
29.  $converter->transform'thumbnail''var/storage/myOriginal3.gif',
30.                         'var/storage/myThumbnail3' )// res: image/.png
31.  
32.  // Animated GIF, will simply be copied!
33.  $converter->transform'thumbnail''var/storage/myOriginal4.gif',
34.                         'var/storage/myThumbnail4' )// res: image/gif

Member Variables

protected ezcImageConverter $converter
The ezcImageConverter
protected array(ezcImageFilter) $filters
Stores the filters utilized by a transformation.
protected ezcImageHandler $lastHandler
The handler last used for filtering.
protected array(string) $mimeOut
Array of MIME types allowed as output for this transformation.

Leave empty, for all MIME types to be allowed.
protected string $name
Stores the name of this transformation.
protected ezcSaveOptions $saveOptions
Options for the final save step.

Method Summary

public ezcImageTransformation __construct( $converter, $name, [$filters = array()], [$mimeOut = array()], [$saveOptions = null] )
Initialize transformation.
public void addFilter( $filter, [$before = null] )
Add a filter to the conversion.
public string getOutMime( $fileIn, [$mimeIn = null] )
Determine output MIME type Returns the MIME type that the transformation will output.
protected void setFilters( $filters )
Set the filters for this transformation.
protected void setMimeOut( $mime )
Sets the MIME types which are allowed for output.
public void setSaveOptions( $options )
Sets the save options.
public void transform( $fileIn, $fileOut )
Apply the given filters for the transformation.

Methods

__construct

ezcImageTransformation __construct( ezcImageConverter $converter, string $name, [ $filters = array()], [ $mimeOut = array()], [ezcImageSaveOptions $saveOptions = null] )
Initialize transformation.

Parameters

Name Type Description
$converter ezcImageConverter The global converter.
$name string Name for the transformation.
$filters array(ezcImageFilter) Filters to apply.
$mimeOut array(string) Output MIME types.
$saveOptions ezcImageSaveOptions Options for saving images.

Throws

ClassDescription
ezcImageMimeTypeUnsupportedException If the output type is unsupported.
ezcImageFiltersException On invalid filter or filter settings error.

addFilter

void addFilter( ezcImageFilter $filter, [int $before = null] )
Add a filter to the conversion.
Adds a filter with the specific settings. Filters can be added either before an existing filter or at the end (leave out $before parameter).

Parameters

Name Type Description
$filter ezcImageFilter The filter definition.
$before int Where to add the filter

Throws

ClassDescription
ezcImageFilterNotAvailableException If the given filter is not available.

getOutMime

string getOutMime( string $fileIn, [string $mimeIn = null] )
Determine output MIME type Returns the MIME type that the transformation will output.

Parameters

Name Type Description
$fileIn string File that should deal as input for the transformation.
$mimeIn string Specify the MIME type, so method does not need to.

Throws

ClassDescription
ezcImageAnalyzerException If the input type is unsupported.

setFilters

void setFilters( $filters )
Set the filters for this transformation.
Checks if the filters defined are available and saves them to the created transformation if everything is okay.

Parameters

Name Type Description
$filters array(ezcImageFilter) Array of filter objects.

Throws

ClassDescription
ezcBaseFileException If the filter array contains invalid object entries.
ezcImageFilterNotAvailableException If a filter is not available.

setMimeOut

void setMimeOut( $mime )
Sets the MIME types which are allowed for output.

Parameters

Name Type Description
$mime array MIME types to allow output for.

Throws

ClassDescription
ezcImageMimeTypeUnsupportedException If the MIME types cannot be used as output of any of the handlers in the converter.

setSaveOptions

void setSaveOptions( ezcImageSaveOptions $options )
Sets the save options.
Sets the save options, that are used for the final save step of the transformation.

Parameters

Name Type Description
$options ezcImageSaveOptions Save options.

transform

void transform( string $fileIn, string $fileOut )
Apply the given filters for the transformation.
Applies the conversion as defined to the given file and saves it as defined.

Parameters

Name Type Description
$fileIn string The file to transform.
$fileOut string The file to save the transformed image to.

Throws

ClassDescription
ezcImageTransformationException If an error occurs during the transformation. The returned exception contains the exception the problem resulted from in it's public $parent attribute.
ezcBaseFileNotFoundException If the file you are trying to transform does not exists.
ezcBaseFilePermissionException If the file you are trying to transform is not readable.

Last updated: Mon, 21 Dec 2009