apply_filter() публичный Метод

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. 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); 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: 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), ));
public apply_filter ( string $filter, mixed $arg1 = '', mixed $arg2 = '', mixed $arg3 = '', mixed $arg4 = '' ) : boolean
$filter string The (case-insensitive) name of the filter to apply. Can be one of the following: - brightness - changes the brightness of the image; use arg1 to set the level of brightness; the range of brightness is -255 to 255; - colorize - adds (subtracts) specified RGB values to each pixel; use arg1, arg2 and arg3 in the form of red, green, blue and arg4 for the alpha channel. the range for each color is -255 to 255 and 0 to 127 for alpha; alpha support is available only for PHP 5.2.5+; - contrast - changes the contrast of the image; use arg1 to set the level of contrast; the range of contrast is -100 to 100; - gausian_blur - blurs the image using the Gaussian method; - grayscale - converts the image into grayscale; - edgedetect - uses edge detection to highlight the edges in the image; - emboss - embosses the image; - mean_removal - uses mean removal to achieve a "sketchy" effect; - negate - reverses all the colors of the image; - pixelate - applies pixelation effect to the image, use arg1 to set the block size and arg2 to set the pixelation effect mode; this filter is available only for PHP 5.3.0+; - selective_blur - blurs the image; - smooth - makes the image smoother. Use arg1 to set the level of smoothness. applies a 9-cell convolution matrix where center pixel has the weight of arg1 and others weight of 1.0. the result is normalized by dividing the sum with arg1 + 8.0 (sum of the matrix). any float is accepted; @param mixed $arg1 Used by the following filters: - brightness - sets the brightness level (-255 to 255) - contrast - sets the contrast level (-100 to 100) - colorize - sets the value of the red component (-255 to 255) - smooth - sets the smoothness level - pixelate - sets the block size, in pixels @param mixed $arg2 Used by the following filters: - colorize - sets the value of the green component (-255 to 255) - pixelate - whether to use advanced pixelation effect or not (defaults to FALSE). @param mixed $arg3 Used by the following filters: - colorize - sets the value of the blue component (-255 to 255) @param mixed $arg4 Used by the following filters: - colorize - 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.
$arg1 mixed
$arg2 mixed
$arg3 mixed
$arg4 mixed
Результат boolean
Пример #1
0
 // and if there is an error, show the error message
 if (!$image->crop(0, 0, 50, 50)) {
     show_error($image->error, $image->source_path, $image->target_path);
 }
 // indicate a target image
 $image->target_path = 'results/rotate.' . $ext;
 // rotate
 // and if there is an error, show the error message
 if (!$image->rotate(45)) {
     show_error($image->error, $image->source_path, $image->target_path);
 }
 // indicate a target image
 $image->target_path = 'results/filter.' . $ext;
 // apply some filters
 // (this combination produces the "sepia" filter)
 $image->apply_filter(array(array('grayscale'), array('colorize', 90, 60, 40)));
 ?>
 <p>Table has background so that transparency can be observed.</p>
 <table style="background:#ABCDEF; border: 2px solid #666">
 	<tr>
         <td width="100" align="center">Resized to 100x100</td>
         <td width="100" align="center">Flipped horizontally</td>
         <td width="100" align="center">Flipped vertically</td>
         <td width="100" align="center">Flipped both horizontally and vertically</td>
         <td width="100" align="center">Cropped from 0, 0 to 50, 50</td>
         <td width="100" align="center">Rotated 45 degrees clockwise</td>
         <td width="100" align="center">Sepia<br>filter</td>
     </tr>
     <tr>
         <td align="center"><img src="results/resize.<?php 
 echo $ext;