react-imagify
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

react-imagify

npm check demo

A small 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

npm install react-imagify

Requirements

  • react >= 16.14

Usage

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 (
    <div>
      <Imagify ref={ref} width={400} height={100}>
        <div style={{ fontSize: "40px" }}>
          <em>I</em> like{" "}
          <span style={{ color: "white", textShadow: "0 0 2px blue" }}>
            cheese
          </span>
        </div>
      </Imagify>
    </div>
  );
};

Limitations

This lib uses foreignObject to draw HTML inside Canvas, so how they would be rendered depends on browsers' implementation.

Readme

Keywords

Package Sidebar

Install

npm i react-imagify

Weekly Downloads

7

Version

0.4.0

License

MIT

Unpacked Size

36.5 kB

Total Files

11

Last publish

Collaborators

  • inokawa