lens-core
Small library that relies on webworkers to apply image transformations.
There are several modules that use lens-core
, check them on the filters folder on the lens repo.
But you can easily create your own transformation function and rely on lens-core
to handle the webworkers and to split the work.
Install
npm install lens-core --save
Methods
getCanvas()
It returns a canvas with the given width and height
; const canvas = ;
convertImageDataToCanvasURL()
Given a ImageData it returns the dataURL
; const canvasURL = ;
applyFilters()
Provide the ImageData, the transformation function, the options to be passed to the transformation function and the number of workers to split the work.
; ;
How to create a custom transformation function?
The transform function receives ImageData, the length of data to transform and the options that the developer provided to image-fiter-core, example transformation function for the threshold effect:
const transform = { for let i = 0; i < length; i += 4 const r = datai; const g = datai + 1; const b = datai + 2; const v = 02126 * r + 07152 * g + 00722 * b >= optionslevel ? 255 : 0; datai = datai + 1 = datai + 2 = v; return data;};