Instafilter\Filter::brightness_contrast PHP Method

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
    public function brightness_contrast($brightness, $contrast)
    {
        //normalise from photoshop's units to imagicks -- this is a guestimate
        $brightness_normalised = abs($brightness) / 150 * 5;
        $contrast_normalised = abs($contrast) / 150 * 5;
        if ($contrast_normalised == 0 and $brightness_normalised == 0) {
            return $this;
        }
        $overlay = new \Imagick();
        $overlay->newPseudoImage(1, 1000, "gradient:");
        $overlay->rotateImage('#fff', 90);
        if ($contrast_normalised != 0) {
            $overlay->sigmoidalContrastImage($contrast > 0, $contrast_normalised, 50);
        }
        if ($brightness_normalised != 0) {
            $overlay->sigmoidalContrastImage($brightness > 0, $brightness_normalised, 0);
        }
        $this->imagick()->clutImage($overlay);
        return $this;
    }