The ImageConversion component provides image manipulation tools. It
enables you to perform filter actions (such as scaling, changing the
colorspace, adding a swirl effect) and to convert between different MIME image
types. Filters and conversions are grouped as
"transformations", which can be globally configured and accessed from anywhere
in the application. Conversions and filters can be performed through different
handlers (currently supported are PHP's GD extension and the external ImageMagick
program). ImageConversion is capable of automatically selecting an appropriate
handler. You can also set handler priorities.

Line 16 shows how a transformation is created. The first parameter to
ezcImageConverter::createTransformation() defines the name of the
transformation, while the second parameter would usually contain filters (which
are not used here). Instead, just one output MIME type is defined as the third
parameter. As a result, this transformation returns images of the type
"image/jpeg".

After instantiating ezcImageConverter, we define the filters to apply. We apply
only one filter in this example. Each filter definition must be an instance of
ezcImageFilter. The first parameter to the constructor of ezcImageFilter
(ezcImageFilter::__construct()) is the name of the filter to use. The second
parameter is an array of settings for the filter. The filter name must
correspond to a method name for one of the filter interfaces:

ezcImageGeometryFilters

ezcImageColorspaceFilters

ezcImageEffectFilters

The settings array must contain all parameters that the specific filter method
expects and the array keys must correspond to the names of the
parameters. For example, the scale filter used here is defined in
ezcImageGeometryFilters::scale(). The available image handlers support the
following filters:

ezcImageGdFilters

ezcImageGeometryFilters

ezcImageColorspaceFilters

ezcImageImagemagickFilters

ezcImageGeometryFilters

ezcImageColorspaceFilters

ezcImageEffectFilters

The filter definition shown here makes ezcImageConverter scale images to a box
of 320x240 pixels. Images will only be scaled if they are larger than the
given size, but not if they are already smaller or fit exactly.

The rest of the example is pretty much the same as example 1. To keep the
example images web-friendly, we use a JPEG image as the source file here:

In this example, there is a second parameter to the constructor of
ezcImageConverterSettings::__construct(), which defines explicit conversions
between MIME types (line 13). In this case, we define that GIF images should be
converted to PNG. When the transformation takes place, it will first check if an
explicit conversion has been defined for the input MIME type. If this is the
case, the explicit conversion will be performed. If not, the first available
output MIME type will be chosen. Note that you have to add the new MIME output
type "image/png" to the allowed output types of the transformation (see line
43).

In the transformation definition we define 3 filters. Note that the
order of filters is important here. The first filter is "scale" again,
after which the colorspace of the image is reduced to greyscale. The last
filter adds a 5-pixel border with a near-white grey value to the image.

This code snippet creates a simple transformation to place the watermark. The
'image' parameter contains the path to the watermark image, while posX and posY
define, where the watermark will be placed on the converted image. The
positions are defined from the bottom left corner, so in this case therer will
be 10 pixel left between the watermark and the image border.

Original image (without watermark):

Converted image (with watermark):

It is also possible to get the size of the watermark image adjusted on the fly
and a second filter is available, which allows to define all values as
percentage values, in respect to the destination image.

While there is also a 'croppedThumbnail' filter available, which croppes
overhead from the scaled image, this filter fills the overhead from scaling
with the given fill color. The image is automatically scaled down to fit the
given thumbnail size.

Original image (original size):

Converted image (thumbnail):

Some JPEG files contain small amounts of corrupt data, which might not result
in problems when viewing these images with your favorite image viewer. However,
GD and ImageMagick by default issue errors for these images. The
ImageConversion component throws an ezcImageFileNotProcessable exception in
this case.

You can avoid this issue in the GD driver, by setting the php.ini directive
"gd.jpeg_ignore_warning" to true. This can either happen in your php.ini
directly or by using the following code in your application, before you attempt
to load any image:

<?php

ini_set("gd.jpeg_ignore_warning",true);

?>

However, it is not recommended to deal with corrupt images like this, since the
results are unpredictable. There is a good chance that the converted image will
be OK, but it is not guaranteed.