# no-canvas-to-image

Rule `unicorn/no-canvas-to-image`. Prefer drawing canvases directly instead of converting them to images.

- Source: unicorn
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 9.9M weekly downloads of presets that enable it
- Trend: +28.3% last quarter
- Rank: #906 by reach, #1161 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/no-canvas-to-image` | no | no | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/no-canvas-to-image.md) |
| Biome | `nursery/noCanvasToImage` | no | no | group nursery, since 2.6.9 | [docs](https://biomejs.dev/linter/rules/no-canvas-to-image/) |

## Code examples

### Incorrect: the rule reports this

```js
const image = await loadImage(canvas.toDataURL());
context.drawImage(image, 0, 0);
```

```js
const imageData = sourceContext.getImageData(0, 0, width, height);
targetContext.putImageData(imageData, 0, 0);
```

### Correct: the rule accepts this

```js
context.drawImage(canvas, 0, 0);
```

```js
targetContext.drawImage(sourceCanvas, 0, 0);
```

```js
const imageData = context.getImageData(0, 0, width, height);
imageData.data[0] = 0;
context.putImageData(imageData, 0, 0);
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/no-canvas-to-image": "error",
    },
  },
];
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "nursery": {
        "noCanvasToImage": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Unicorn recommended](https://lintradar.dev/presets/unicorn-recommended.md) | ESLint | `eslint-plugin-unicorn` | 340 | 9.5M | +30.3% |
| [Unicorn unopinionated](https://lintradar.dev/presets/unicorn-unopinionated.md) | ESLint | `eslint-plugin-unicorn` | 236 | 9.5M | +30.3% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [unicorn/better-dom-traversing](https://lintradar.dev/rules/unicorn/better-dom-traversing.md): Prefer better DOM traversal APIs.
- [unicorn/no-collection-bracket-access](https://lintradar.dev/rules/unicorn/no-collection-bracket-access.md): Disallow accessing `Map`, `Set`, `WeakMap`, and `WeakSet` entries with bracket notation.
- [unicorn/prefer-top-level-await](https://lintradar.dev/rules/unicorn/prefer-top-level-await.md): Prefer top-level await over top-level promises and async function calls.
- [unicorn/no-constant-zero-expression](https://lintradar.dev/rules/unicorn/no-constant-zero-expression.md): Disallow arithmetic and bitwise operations that always evaluate to `0`.
- [unicorn/prefer-string-raw](https://lintradar.dev/rules/unicorn/prefer-string-raw.md): Prefer using the `String.raw` tag to avoid escaping `\`.
- [unicorn/no-negated-comparison](https://lintradar.dev/rules/unicorn/no-negated-comparison.md): Disallow negated comparisons.

---

Web page: https://lintradar.dev/rules/unicorn/no-canvas-to-image. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
