# generate-image

> Generate images in browser and node.

Latest version **1.0.1** (published 2019-09-04) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-09-04 |
| First published | 2019-09-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 18 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | LearnShare |
| Maintainers | learnshare |
| Keywords | generate, image, browser, node |

## Links

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

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2019-09-04
- 1.0.0 — 2019-09-04

## README

# Generate Image

Generate images in browser and node.

## Installation and Usage

```
npm install --save generate-image
```

### In Browser

```js
import GenerateImage from 'generate-image';
```

or

```html
<script src="path/to/generate-image.min.js"></script>
```

1\. Automatic:

```html
<img src="" data-gi="w=300&h=150&c='Hello World'">

<script>
  document.addEventListener('load', () => {
    GenerateImage.auto('data-gi');
  });
</script>
```

2\. Programmatic:

```js
const target = document.getElementById('image-target');

const imageData = GenerateImage({
  w: 300,
  h: 150,
  t: 'diagonal',
  c: 'Hello World',
});
target.src = imageData;
```

### In Node

```js
const GenerateImage = require('generate-image');

const imageData = GenerateImage({
  w: 300,
  h: 150,
});
```

## API

### GenerateImage.auto(attr)

| argument | required | default | info |
|----------|----------|---------|------|
| attr     | -        | 'data-gi' | data attr that provide option string for `<img>` |

### GenerateImage(options, encode)

| argument | required | default | info |
|----------|----------|---------|------|
| options  | -        | -       | [options](#options) |
| encode   | -        | true    | return dataURI or pure xml |

### options

| argument | required | default | info |
|----------|----------|---------|------|
| w        | -        | 300     | width |
| h        | -        | 150     | height |
| bc       | -        | '#F2F2F6' | background color |
| fc       | -        | '#666'  | foreground color |
| t        | -        | ''      | texture: 'diagonal' |
| c        | -        | ''      | text content |

## SVG template

```xml
<svg
    version="1.1"
    baseProfile="full"
    width="{ w }"
    height="{ h }"
    viewBox="0 0 { w } { h }"
    xmlns="http://www.w3.org/2000/svg">
  <!-- background color -->
  <rect
      width="100%"
      height="100%" 
      fill="{ bc }" />

  <!-- texture: diagonal -->
  <line
      x1="0"
      y1="0"
      x2="{ w }"
      y2="{ h }"
      stroke="{ fc }"
      stroke-width="1"
      stroke-opacity="0.6" />
  <line
      x1="0"
      y1="{ h }"
      x2="{ w }"
      y2="0"
      stroke="{ fc }"
      stroke-width="1"
      stroke-opacity="0.6" />

  <!-- text content -->
  <text
      x="{ w / 2 }"
      y="{ h / 2 }"
      text-anchor="middle"
      fill="{ fc }">{ c }</text>
</svg>
```

### License

[MIT](./LICENSE)

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