PHP Class Instafilter\Filter

This holds all of the common things between filters like getting access to the imagemagick instance etc.
Exibir arquivo Open project: fbf/instafilter Class Usage Examples

Public Methods

Method Description
__construct ( array $configuration = [] )
apply_filter ( ) You should only call this when you're ready to save, it often overwrites your image a few times (not always though) *
brightness_contrast ( integer $brightness, integer $contrast ) : Filter Replicate brightness/contrast photoshop function
colorize ( string $color, integer $composition = Imagick::COMPOSITE_MULTIPLY ) : Filter Replicate Colorize function
curves ( array $points, integer $channel = null ) : Filter Replicate photoshop's curves function
curves_graph ( string $fx ) : Filter Perform an imagemagick-style function on each pixel
exec ( string $command, string $params ) : Filter Execute a manual CLI command -- normally used when there's no PHP alternatice
gamma ( float $gamma, integer $channel = null ) : Filter Change the gamma of an image
hsl ( integer $hue, integer $saturation, integer $lightness ) : Filter Replicate HSL function
image ( &$image = null )
imagick ( &$imagick = null ) This is the imagemagick instance to perform the filters on
levels ( float $gamma = 1, integer $input_min, integer $input_max = 255, integer $output_min, integer $output_max = 255, integer $channel = Imagick::CHANNEL_ALL ) : Filter Replicate Photoshop's levels function.
vignette ( string $color, integer $composition = Imagick::COMPOSITE_DEFAULT, float $crop_factor = 1.5 ) : Filter Adds a vignette to the image

Private Methods

Method Description
_exec ( type $program, type $params, type $passthru = false ) : type Execute the command

Method Details

__construct() public method

public __construct ( array $configuration = [] )
$configuration array

apply_filter() abstract public method

You should only call this when you're ready to save, it often overwrites your image a few times (not always though) *
abstract public apply_filter ( )

brightness_contrast() public method

Now this one is a bit of a pain. PHP's extension doesn't provide us with this handle (yet?) So we have to save the image to disk at this point, perform the function using the command line, and reload the image. yay.
public brightness_contrast ( integer $brightness, integer $contrast ) : Filter
$brightness integer this is should be -150 <= brightnes <= 150. 0 for no change.
$contrast integer this is should be -150 <= contrast <= 150. 0 for no change.
return Filter

colorize() public method

Replicate Colorize function
public colorize ( string $color, integer $composition = Imagick::COMPOSITE_MULTIPLY ) : Filter
$color string a hex or rgb(a) color
$composition integer use imagicks constants here
return Filter

curves() public method

This takes a series of points and generates a function for the graph that fits the points. That function is then applied to each pixes, as in photoshop. It should use curves_graph once the function has been generated.
public curves ( array $points, integer $channel = null ) : Filter
$points array an array of arrays. array(array(12, 32), array(32,56)) etc.
$channel integer use imagemagicks contants here
return Filter

curves_graph() public method

Perform an imagemagick-style function on each pixel
public curves_graph ( string $fx ) : Filter
$fx string the function
return Filter

exec() public method

Execute a manual CLI command -- normally used when there's no PHP alternatice
public exec ( string $command, string $params ) : Filter
$command string normally 'convert'
$params string the CLI params
return Filter

gamma() public method

Change the gamma of an image
public gamma ( float $gamma, integer $channel = null ) : Filter
$gamma float normally between 0.8 and 2
$channel integer Use the Imagick constants for this
return Filter

hsl() public method

Imagemagick calls this 'modulate '
public hsl ( integer $hue, integer $saturation, integer $lightness ) : Filter
$hue integer -100 <= hue <= 100. 0 is no change.
$saturation integer -100 <= hue <= 100. 0 is no change.
$lightness integer -100 <= hue <= 100. 0 is no change.
return Filter

image() public method

public image ( &$image = null )

imagick() public method

It's recommended you supply a temporary file here! Some functions, such as brightness_contrast, overwrite the image.
public imagick ( &$imagick = null )

levels() public method

Replicate Photoshop's levels function.
public levels ( float $gamma = 1, integer $input_min, integer $input_max = 255, integer $output_min, integer $output_max = 255, integer $channel = Imagick::CHANNEL_ALL ) : Filter
$gamma float
$input_min integer between 0 and 255, same as photoshops
$input_max integer between 0 and 255, same as photoshops
$output_min integer between 0 and 255, same as photoshops
$output_max integer between 0 and 255, same as photoshops
$channel integer use imagemagicks constants
return Filter

vignette() public method

Adds a vignette to the image
public vignette ( string $color, integer $composition = Imagick::COMPOSITE_DEFAULT, float $crop_factor = 1.5 ) : Filter
$color string the colour of the vignette
$composition integer an imagick constant defining the composition to use
$crop_factor float defines the strenth of the vignette
return Filter