# lens-core

> Core module for lens-filter

Latest version **0.0.8** (published 2018-06-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install lens-core
pnpm add lens-core
yarn add lens-core
bun add lens-core
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2018-06-10 |
| First published | 2018-06-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 158.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Ricardo Canastro |
| Maintainers | canastro |
| Keywords | image, filter, filters, processing, manipulation, contrast, transformation, pixel |

## Links

- npm: https://www.npmjs.com/package/lens-core
- Repository: https://github.com/canastro/lens
- Homepage: https://github.com/canastro/lens#readme
- Issues: https://github.com/canastro/lens/issues
- npm.io page: https://npm.io/package/lens-core

## Dependencies (1)

- [workerize](https://npm.io/package/workerize.md) ^0.1.7

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.8 (latest) — 2018-06-10
- 0.0.7 — 2018-06-10
- 0.0.6 — 2018-06-09
- 0.0.5 — 2018-06-06
- 0.0.4 — 2018-06-05
- 0.0.2 — 2018-06-04
- 0.0.1 — 2018-06-04

## README

[![npm version](https://badge.fury.io/js/lens-core.svg)](https://badge.fury.io/js/lens-core)

# 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](https://github.com/canastro/lens/tree/master/packages/filters).

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
```js
import { getCanvas } from 'lens-core';

const canvas = getCanvas(100, 100);
```

### convertImageDataToCanvasURL()
Given a ImageData it returns the dataURL
```js
import { convertImageDataToCanvasURL } from 'lens-core';

const canvasURL = convertImageDataToCanvasURL(imageData);
```

### 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.

```js
import { applyFilters } from 'lens-core';

applyFilters({ 
    data: 'image-data', 
    transform: transformationFunction, 
    options: {},  // options that are passed to the transformation function
    nWorkers: 4 // number of webworkers to transform the image
}).then(imageData => {
    // Do whatever you want with imageData
});
```

# 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:

```js
const transform = ({ data, length, options }) => {
    for (let i = 0; i < length; i += 4) {
        const r = data[i];
        const g = data[i + 1];
        const b = data[i + 2];
        const v = (0.2126 * r + 0.7152 * g + 0.0722 * b >= options.level) ? 255 : 0;
        data[i] = data[i + 1] = data[i + 2] = v;
    }

    return data;
};
```

---
_Source: https://npm.io/package/lens-core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
