An open API service indexing awesome lists of open source software.

https://github.com/inokawa/react-imagify

A small React component to render HTML as Canvas.
https://github.com/inokawa/react-imagify

Last synced: 6 months ago
JSON representation

A small React component to render HTML as Canvas.

Awesome Lists containing this project

README

          

# react-imagify

![npm](https://img.shields.io/npm/v/react-imagify) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/react-imagify) [![check](https://github.com/inokawa/react-imagify/actions/workflows/check.yml/badge.svg)](https://github.com/inokawa/react-imagify/actions/workflows/check.yml) [![demo](https://github.com/inokawa/react-imagify/actions/workflows/demo.yml/badge.svg)](https://github.com/inokawa/react-imagify/actions/workflows/demo.yml)

A small [React](https://github.com/facebook/react) component to render HTML as Canvas.

## Why?

Drawing HTML on Canvas is useful to apply some effect through Canvas and easy to save as image.

This component renders usual JSX on Canvas without any context switch, and does not require any heavy dependencies like three.js.

## Demo

https://inokawa.github.io/react-imagify/

## Install

```sh
npm install react-imagify
```

### Requirements

- react >= 16.14

## Usage

```jsx
import { useRef, useEffect } from "react";
import { Imagify } from "react-imagify";

export const Component = () => {
const ref = useRef(null);
useEffect(() => {
// do something
const canvasElement = ref.current;
}, []);

return (




I like{" "}

cheese




);
};
```

## Limitations

This lib uses [foreignObject](https://developer.mozilla.org/docs/Web/SVG/Element/foreignObject) to draw HTML inside Canvas, so how they would be rendered depends on browsers' implementation.