css-js-filter
Set of predefined CSS filters realised via JS along with
utils to create your own.
Usage
Using predefined filters
With Javascript
If we want to modify images directly, we have to use filter's
JS part.
import {BrightnessFilter} from 'css-js-filter';
const canvas = document.getElementById('canvas');
const context = canvas.getContext('2d');
const imageData = context.getImageData(0, 0, canvas.width, canvas.height);
const modifiedBytes = BrightnessFilter.applyTo(imageData.data, 30);
const modifiedImageData = new ImageData(modifiedBytes, imageData.width, imageData.height);
const modifiedImageData = BrightnessFilter.applyTo(imageData, 30);
context.putImageData(modifiedImageData, 0, 0);
With CSS
In case when there is no real need to modify pixels directly, it is
strongly recommended to use CSS way. Remember, that use of CSS works much
faster than JS does. Let's look how it works.
import {BrightnessFilter} from 'css-js-filter';
const canvas = document.getElementById('canvas');
const cssFilter = BrightnessFilter.getCSSFilter(30);
canvas.style.filter = cssFilter;
Of course, you could use those filters not only for canvas but the other
html elements. It only generates a string, compatible for CSS's filter
property.