How to set image brightness to back it's original brightness?

1.2k Views Asked by At

I am using Pixastic for performins image operations. Currently I am using it's Brightness/Contrast Code.

Here is the HTML Code

<input type="range" id="brightness_range"  min="-150" max="150" value="0" />

and this is jQuery code of Pixastic

jQuery('#brightness_range').change(function(){
        var img = document.getElementById ('image');
        var brightness_val = parseInt(jQuery('#brightness_range').val());
        Pixastic.process(img, "brightness", {brightness:brightness_val});
    });

I am able to set it's brightness but I am not able to take it to back.

Let me explain... For example I changed Slider value to 25 then brightness set to 25 but if I drag my slider value to 0 again from 25 then it's not setting the original brightness of Image... :(

I think it is adding value every time first 25 then plus 25 (50) .

Please guys help me I asked similar questions yesturday but not getting any response from stackoverflow .

And I think there is no other option to change brightness of image using slider or if Please tell me.

Thanks!!!

1

There are 1 best solutions below

0
user3087157 On

Every pixastic action is performed -on top of- the canvas. So actually you are first doing a brightness of 25, and then a brightness of 0 (which is doing nothing).

To make this work as you expect, change your code to the following:

jQuery('#brightness_range').change(function(){
    var img = document.getElementById ('image');
    var brightness_val = parseInt(jQuery('#brightness_range').val());
    Pixastic.revert(img); // Note that this is an undocumented feature, but it exists.
    Pixastic.process(img, "brightness", {brightness:brightness_val});
});