# simple2canvas

> generate image with json data by canvas

Latest version **0.3.0** (published 2022-09-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install simple2canvas
pnpm add simple2canvas
yarn add simple2canvas
bun add simple2canvas
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2022-09-10 |
| First published | 2020-02-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 55.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 25 |
| Author | lizheming |
| Maintainers | lizheming |
| Keywords | canvas, json, image, generate, simple2canvas, html2canvas |

## Links

- npm: https://www.npmjs.com/package/simple2canvas
- Repository: https://github.com/lizheming/Simple2Canvas
- Homepage: https://github.com/lizheming/Simple2Canvas#readme
- Issues: https://github.com/lizheming/Simple2Canvas/issues
- npm.io page: https://npm.io/package/simple2canvas

## Dependencies (1)

- [canvas](https://npm.io/package/canvas.md) ^2.6.1

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.3.0 (latest) — 2022-09-10
- 0.2.0 — 2020-03-31
- 0.1.0 — 2020-02-23

## README

# Simple2Canvas
Generate image with json data by canvas https://simple2canvas.netlify.com/

## Installation

You can install it with npm or `<script>`:

```bash
npm install simple2canvas --save-dev
```

```html
<script src="https://unpkg/simple2canvas/dist/simplecanvas.umd.min.js"></script>
```

## Usage

```js
const simple2canvas = require('simple2canvas');
const options = {
  width: 360,
  height: 360,
  rate: 2,
  elements: [
    {
      type: 'rect',
      width: 360,
      height: 360,
      top: 0,
      left: 0,
      fill: '#FFF'
    },
    {
      type: 'text',
      text: 'Hello World!',
      top: 10, 
      left: 10,
      fontSize: 18,
      lineHeight: 18,
      color: 'black'
    }
  ]
};

(async() => {
  const canvas = await simple2canvas(options);
  
  const img = document.createElement('img');
  img.style.width = options.width + 'px';
  img.style.height = options.height + 'px';
  img.src = canvas.toDataURL();
  document.body.appendChild(img);
})();
```

## Configuration

| name | required | default | description |
|------|:----------:|:---------:|-------------|
| width | ✔️ | | canvas width |
| height | ✔️ | | canvas height |
| rate | | 1 | canvas pixel ratio |
| render | | 'html' | canvas render |
| elements | | [] | canvas elements |

### Elements Configuration

#### rect

- `top`
- `left`
- `width`
- `height`
- `fill`
- `round`

#### image

- `top`
- `left`
- `width`
- `height`
- `url`

#### text

- `top`
- `left`
- `fontSize`
- `lineHeight`
- `text`
- `color`
- `textAlign`
- `fontWeight`
- `fontFamily`

## Example
run npm start and open http://localhost:3000

online example: https://simple2canvas.netlify.com/

## License
simple2canvas is released under the MIT license.

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