https://github.com/davidenke/context-filter-polyfill
Polyfills `CanvasRenderingContext2d.filter` capability of adopting CSS3 filters to canvas contexts at least partially.
https://github.com/davidenke/context-filter-polyfill
canvas2d context filter polyfill
Last synced: 3 months ago
JSON representation
Polyfills `CanvasRenderingContext2d.filter` capability of adopting CSS3 filters to canvas contexts at least partially.
- Host: GitHub
- URL: https://github.com/davidenke/context-filter-polyfill
- Owner: davidenke
- License: mit
- Created: 2019-04-07T01:11:40.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2025-01-12T00:01:10.000Z (6 months ago)
- Last Synced: 2025-04-12T14:18:52.923Z (3 months ago)
- Topics: canvas2d, context, filter, polyfill
- Language: TypeScript
- Size: 1.28 MB
- Stars: 97
- Watchers: 3
- Forks: 23
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# context-filter-polyfill
[](https://github.com/davidenke/context-filter-polyfill)
[![NPM Version][npm-version-image]][npm-url]
[![NPM Install Size][npm-install-size-image]][npm-install-size-url]Examples: https://davidenke.github.io/context-filter-polyfill/
Polyfills [`CanvasRenderingContext2d`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D) and [`OffscreenCanvasRenderingContext2d`](https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvasRenderingContext2d) capability of adopting [CSS3 filters](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/filter) on canvas contexts (at least partially).
Right now ~~only WebKit [misses an implementation (Bugzilla #198416)](https://bugs.webkit.org/show_bug.cgi?id=198416)~~ all engines support it natively, despite Safari not having shipped it yet in the stable release channel.
## Installation
Add the polyfill to your page via script tag from a CDN:
```html
```
Or from npm:
```bash
npm install context-filter-polyfill
```... and import it in your code:
```js
import 'context-filter-polyfill';
```## Changes in 0.3.14
Since version 0.3.14 the method of how the polyfill is applied has been reworked.
It now polyfills the filter on each drawing function call instead of applying it once on the context in the end.This results in more accurate behavior compared to the previous implementation.
The [polyfilled and native results](https://davidenke.github.io/context-filter-polyfill/) can be compared with a non-WebKit browser like Firefox or Chrome.
## Supported filters
- [`url`]() ✗
- [`blur`]() ✔
- [`brightness`]() ✔
- [`contrast`]() ✔
- [`drop-shadow`]() ✔
- [`grayscale`]() ✔
- [`hue-rotate`]() ✔
- [`invert`]() ✔
- [`none`]() ✔
- [`opacity`]() ✔
- [`saturate`]() ✔
- [`sepia`]() ✔## See it in action
Just open the [integration demo](https://davidenke.github.io/context-filter-polyfill/) on Safari / iOS.
## License
[MIT](LICENSE)
[npm-install-size-image]: https://badgen.net/packagephobia/install/context-filter-polyfill
[npm-install-size-url]: https://packagephobia.com/result?p=context-filter-polyfill
[npm-url]: https://npmjs.org/package/context-filter-polyfill
[npm-version-image]: https://badgen.net/npm/v/context-filter-polyfill