Normalize CSS filters with GD lib filters

140 views Asked by At

I want to make the user drag a rangeslider and adjust brightness and contrast of an image with live preview ( CSS filters ) and then save the adjustments with GD lib.

However i can't seem to get the same result from CSS filters and GD lib BRIGHTNESS and CONTRAST filters.

My css filters are ranging from 50% - 150% with 100% being no effect.

PHP conversion at the moment:

    // Convert palette images to true color RGB images
    imagepalettetotruecolor($image);

    if( isset($opt['brightness']) ) {
        $normalize = $opt['brightness'] / 100;
        $brightness = (255 - (255 * $normalize )) * -1;
        imagefilter($image, IMG_FILTER_BRIGHTNESS, $brightness);
    }

    if( isset($opt['contrast']) ) {
        $contrast = -($opt['contrast'] - 100);
        imagefilter($image, IMG_FILTER_CONTRAST, $contrast);
    }

    imagejpeg($image, $plain_img_path);

CSS filters are the ones with sliders. GD lib without.

Low contrast:

enter image description here

enter image description here

High Brightness:

Brightness GD lib Brightness CSS

0

There are 0 answers