Vendor/ZebraImage.class.php
function apply_filter($filter, $arg1 = '', $arg2 = '', $arg3 = '', $arg4 = '')
    {

        // if "imagefilter" function exists and the requested filter exists
        if (function_exists('imagefilter')) // if image resource was successfully created
        {
            if ($this->_create_from_source()) {

                // prepare the target image
                $target_identifier = $this->_prepare_image($this->source_width, $this->source_height, -1);

                // copy the original image
                imagecopyresampled(

                    $target_identifier,
                    $this->source_identifier,
                    0,
                    0,
                    0,
                    0,
                    $this->source_width,
                    $this->source_height,
                    $this->source_width,
                    $this->source_height

                );

                // if multiple filters are to be applied at once
                if (is_array($filter)) {

                    // iterate through the filters
                    foreach ($filter as $arguments) // if filter exists
                    {
                        if (defined('IMG_FILTER_' . strtoupper($arguments[0]))) {

                            // try to apply the filter...
                            if (!@call_user_func_array(
                                'imagefilter',
                                array_merge(
                                    array($target_identifier, constant('IMG_FILTER_' . strtoupper($arguments[0]))),
                                    array_slice($arguments, 1)
                                )
                            )
                            ) // ...and trigger an error if the filter could not be applied
                            {
                                trigger_error(
                                    'Invalid arguments used for "' . strtoupper($arguments[0]) . '" filter',
                                    E_USER_WARNING
                                );
                            }

                            // if filter doesn't exists, trigger an error
                        } else {
                            trigger_error(
                                'Filter "' . strtoupper($arguments[0]) . '" is not available',
                                E_USER_WARNING
                            );
                        }
                    }

                    // if a single filter is to be applied and it is available
                } elseif (defined('IMG_FILTER_' . strtoupper($filter))) {

                    // get all the arguments passed to the method
                    $arguments = func_get_args();

                    // try to apply the filter...
                    if (!@call_user_func_array(
                        'imagefilter',
                        array_merge(
                            array($target_identifier, constant('IMG_FILTER_' . strtoupper($filter))),
                            array_slice($arguments, 1)
                        )
                    )
                    ) // ...and trigger an error if the filter could not be applied
                    {
                        trigger_error(
                            'Invalid arguments used for "' . strtoupper($arguments[0]) . '" filter',
                            E_USER_WARNING
                        );
                    }

                    // if filter doesn't exists, trigger an error
                } else {
                    trigger_error('Filter "' . strtoupper($arguments[0]) . '" is not available', E_USER_WARNING);
                }

                // write image
                return $this->_write_image($target_identifier);

            }
        }

        // if script gets this far, return false
        // note that we do not set the error level as it has been already set
        // by the _create_from_source() method earlier, if the case
        return false;

    }
function apply_filter($filter, $arg1 = '', $arg2 = '', $arg3 = '', $arg4 = '')
    {

        // if "imagefilter" function exists and the requested filter exists
        if (function_exists('imagefilter')) // if image resource was successfully created
        {
            if ($this->_create_from_source()) {

                // prepare the target image
                $target_identifier = $this->_prepare_image($this->source_width, $this->source_height, -1);

                // copy the original image
                imagecopyresampled(

                    $target_identifier,
                    $this->source_identifier,
                    0,
                    0,
                    0,
                    0,
                    $this->source_width,
                    $this->source_height,
                    $this->source_width,
                    $this->source_height

                );

                // if multiple filters are to be applied at once
                if (is_array($filter)) {

                    // iterate through the filters
                    foreach ($filter as $arguments) // if filter exists
                    {
                        if (defined('IMG_FILTER_' . strtoupper($arguments[0]))) {

                            // try to apply the filter...
                            if (!@call_user_func_array(
                                'imagefilter',
                                array_merge(
                                    array($target_identifier, constant('IMG_FILTER_' . strtoupper($arguments[0]))),
                                    array_slice($arguments, 1)
                                )
                            )
                            ) // ...and trigger an error if the filter could not be applied
                            {
                                trigger_error(
                                    'Invalid arguments used for "' . strtoupper($arguments[0]) . '" filter',
                                    E_USER_WARNING
                                );
                            }

                            // if filter doesn't exists, trigger an error
                        } else {
                            trigger_error(
                                'Filter "' . strtoupper($arguments[0]) . '" is not available',
                                E_USER_WARNING
                            );
                        }
                    }

                    // if a single filter is to be applied and it is available
                } elseif (defined('IMG_FILTER_' . strtoupper($filter))) {

                    // get all the arguments passed to the method
                    $arguments = func_get_args();

                    // try to apply the filter...
                    if (!@call_user_func_array(
                        'imagefilter',
                        array_merge(
                            array($target_identifier, constant('IMG_FILTER_' . strtoupper($filter))),
                            array_slice($arguments, 1)
                        )
                    )
                    ) // ...and trigger an error if the filter could not be applied
                    {
                        trigger_error(
                            'Invalid arguments used for "' . strtoupper($arguments[0]) . '" filter',
                            E_USER_WARNING
                        );
                    }

                    // if filter doesn't exists, trigger an error
                } else {
                    trigger_error('Filter "' . strtoupper($arguments[0]) . '" is not available', E_USER_WARNING);
                }

                // write image
                return $this->_write_image($target_identifier);

            }
        }

        // if script gets this far, return false
        // note that we do not set the error level as it has been already set
        // by the _create_from_source() method earlier, if the case
        return false;

    }
Applies one or more filters to the image given as {@link source_path} and outputs it as the file specified as
{@link target_path}.

<samp>This method is available only if the {@link http://php.net/manual/en/function.imagefilter.php imagefilter}
function is available (available from PHP 5+), and will leave images unaltered otherwise.</samp>

<code>
// include the Zebra_Image library
require 'path/to/Zebra_Image.php';

// instantiate the class
$img = new Zebra_Image();

// a source image
$img->source_path = 'path/to/source.ext';

// path to where should the resulting image be saved
// note that by simply setting a different extension to the file will
// instruct the script to create an image of that particular type
$img->target_path = 'path/to/target.ext';

// apply the "grayscale" filter
$img->apply_filter('grayscale');

// apply the "contrast" filter
$img->apply_filter('contrast', -20);
</code>

You can also apply multiple filters at once. In this case, the method requires a single argument, an array of
arrays, containing the filters and associated arguments, where applicable:

<code>
// create a sepia effect
// note how we're applying multiple filters at once
// each filter is in its own array
$img->apply_filter(array(

// first we apply the "grayscale" filter
array('grayscale'),

// then we apply the "colorize" filter with 90, 60, 40 as
// the values for red, green and blue
array('colorize', 90, 60, 40),

));
</code>

@param  string $filter The (case-insensitive) name of the filter to apply. Can be one of the following:

-   <b>brightness</b>       -   changes the brightness of the image; use <b>arg1</b>
to set the level of brightness; the range of brightness
is -255 to 255;
-   <b>colorize</b>         -   adds (subtracts) specified RGB values to each pixel;
use <b>arg1</b>, <b>arg2</b> and <b>arg3</b> in the
form of red, green, blue and <b>arg4</b> for the alpha
channel. the range for each color is -255 to 255 and
0 to 127 for alpha; <i>alpha support is available only
for PHP 5.2.5+</i>;
-   <b>contrast</b>         -   changes the contrast of the image; use <b>arg1</b>
to set the level of contrast; the range of contrast
is -100 to 100;
-   <b>gausian_blur</b>     -   blurs the image using the Gaussian method;
-   <b>grayscale</b>        -   converts the image into grayscale;
-   <b>edgedetect</b>       -   uses edge detection to highlight the edges in the image;
-   <b>emboss</b>           -   embosses the image;
-   <b>mean_removal</b>     -   uses mean removal to achieve a "sketchy" effect;
-   <b>negate</b>           -   reverses all the colors of the image;
-   <b>pixelate</b>         -   applies pixelation effect to the image, use <b>arg1</b>
to set the block size and <b>arg2</b> to set the
pixelation effect mode; <i>this filter is available
only for PHP 5.3.0+</i>;
-   <b>selective_blur</b>   -   blurs the image;
-   <b>smooth</b>           -   makes the image smoother. Use <b>arg1</b> to set the
level of smoothness. applies a 9-cell convolution matrix
where center pixel has the weight of <b>arg1</b> and
others weight of 1.0. the result is normalized by dividing
the sum with <b>arg1</b> + 8.0 (sum of the matrix).
any float is accepted;

@param  mixed $arg1 Used by the following filters:
-   <b>brightness</b>       -   sets the brightness level (-255 to 255)
-   <b>contrast</b>         -   sets the contrast level (-100 to 100)
-   <b>colorize</b>         -   sets the value of the red component (-255 to 255)
-   <b>smooth</b>           -   sets the smoothness level
-   <b>pixelate</b>         -   sets the block size, in pixels

@param  mixed $arg2 Used by the following filters:
-   <b>colorize</b>         -   sets the value of the green component (-255 to 255)
-   <b>pixelate</b>         -   whether to use advanced pixelation effect or not (defaults to FALSE).

@param  mixed $arg3 Used by the following filters:
-   <b>colorize</b>         -   sets the value of the blue component (-255 to 255)

@param  mixed $arg4 Used by the following filters:
-   <b>colorize</b>         -   alpha channel; a value between 0 and 127. 0 indicates
completely opaque while 127 indicates completely
transparent.

@since 2.2.2

@return boolean             Returns TRUE on success or FALSE on error.

If {@link http://php.net/manual/en/function.imagefilter.php imagefilter} is not
available the method will return FALSE without setting an {@link error} code.

If the requested filter doesn't exist, or invalid arguments are passed, the method
will trigger a warning.

If FALSE is returned and you are sure that
{@link http://php.net/manual/en/function.imagefilter.php imagefilter} exists and that
the requested filter is valid, check the {@link error} property to see the error code.