Instafilter\Filter::levels PHP Method

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
    public function levels($gamma = 1, $input_min = 0, $input_max = 255, $output_min = 0, $output_max = 255, $channel = \Imagick::CHANNEL_ALL)
    {
        $range = $this->imagick()->getQuantumRange();
        $range = $range['quantumRangeLong'];
        //convert photoshop's units to imagemagicks
        $input_min = round($input_min / 255 * $range);
        $input_max = round($input_max / 255 * $range);
        $output_min = round($output_min / 255 * $range);
        $output_max = round($output_max / 255 * $range);
        // set input levels
        $this->imagick()->levelImage($input_min, $gamma, $input_max, $channel);
        // set output levels
        $this->imagick()->levelImage(-$output_min, 1.0, $range + ($range - $output_max), $channel);
        return $this;
    }