Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opacity Filter for image is not there. #230

Open
inkxe-vasanth opened this issue Sep 18, 2018 · 1 comment
Open

Opacity Filter for image is not there. #230

inkxe-vasanth opened this issue Sep 18, 2018 · 1 comment

Comments

@inkxe-vasanth
Copy link

inkxe-vasanth commented Sep 18, 2018

We need opacity for the image -

I have added this code to camenjs, it's working for me fine. Review the code add it if feel useful.

Code

Filter.register("opacity", function (adjust) {
        adjust = Math.floor(255 * (adjust / 100)); 
        var imageData = this.imageData.data,
            length = imageData.length;
        // set every fourth value to 50
        for (var i = 3; i < length; i += 4) {
            imageData[i] = imageData[i] == 0 ? imageData[i] : adjust;
        }
        // after the manipulation, reset the data
        this.imageData.data = imageData;
        this.context.putImageData(this.imageData, 0, 0); 
    });
@av01d
Copy link

av01d commented May 2, 2019

This works better:

Caman.Filter.register('opacity', function(adjust) {
	adjust = Math.floor(255 * (adjust / 100));
	var inputData = this.pixelData, length = inputData.length;
	// Adjust alpha channel (every 4th value):
	for (var i = 3; i < length; i += 4) {
		inputData[i] = inputData[i] == 0 ? 0 : adjust;
	}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants