# image-refractor

> A canvas-based web-component for applying webgl refaction shader effects to images

Latest version **0.1.2** (published 2025-12-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install image-refractor
pnpm add image-refractor
yarn add image-refractor
bun add image-refractor
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; no vulnerabilities; has provenance.

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

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2025-12-11 |
| First published | 2023-11-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 35.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 6 |
| Author | Marc Anton Dahmen |
| Maintainers | marcantondahmen |
| Keywords | shader, webgl, canvas |

## Links

- npm: https://www.npmjs.com/package/image-refractor
- Repository: https://github.com/marcantondahmen/image-refractor
- Homepage: https://github.com/marcantondahmen/image-refractor#readme
- Issues: https://github.com/marcantondahmen/image-refractor/issues
- npm.io page: https://npm.io/package/image-refractor

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 0.1.2 (latest) — 2025-12-11
- 0.1.1 — 2023-11-15
- 0.1.0 — 2023-11-13

## README

# Image Refractor

A canvas-based web-component for applying animated water-like refraction effects to images.

[![](assets/readme.png)](https://marcantondahmen.github.io/image-refractor/)

:wave: [Check out the demo](https://marcantondahmen.github.io/image-refractor/)

## Getting Started

You can either install this [package](https://www.npmjs.com/package/image-refractor)
with `npm` and import it into your JavaScript or TypeScript project or use it in a browser.

### NPM

Install with `npm`:

```bash
npm i --save image-refractor
```

Import into your project as follows in order to register the custom web-component:

```javascript
import 'image-refractor';
```

### CDN

Alternatively just load it from a CDN as follows:

```html
<script src="https://unpkg.com/image-refractor/dist/image-refractor.js"></script>
```

## Usage

After importing the component, it can simply be used like any other HTML element:

```html
<image-refractor
  width="1000"
  height="1000"
  refract="1.333"
  speed="0.03"
  intensity="1.0"
  src="https://domain.com/image.png"
></image-refractor>
```

## Options

The component can be configured using the following attributes:

| Attribute   | Description                                                                                           |
| ----------- | ----------------------------------------------------------------------------------------------------- |
| `src`       | The texture image                                                                                     |
| `width`     | The rendered image width in pixels. This describes the canvas resolution.                             |
| `height`    | The rendered image height in pixels. Also here, the height is used to describe the canvas resolution. |
| `refract`   | The refraction index that is used.                                                                    |
| `speed`     | The animation speed. Good values are between `0.01` and `0.1`.                                        |
| `intensity` | The intensity of the underlaying noise. Higher values generate higher distortion.                     |

Check out the [source](demo/index.html#L31) of the demo page for some configuration examples.

## Acknowledgements

Thanks to **SuperHi** for the great inspiration [video](https://www.youtube.com/watch?v=GALjY57ntsk) and
[Yi-Wen Lin](https://github.com/yiwenl) for his [fbm](https://github.com/yiwenl/glsl-fbm/blob/master/2d.glsl) implementation.

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