Git Product home page Git Product logo

generate-image's Introduction

Generate Image

Generate images in browser and node.

Installation and Usage

npm install --save generate-image

In Browser

import GenerateImage from 'generate-image';

or

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

1. Automatic:

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

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

2. Programmatic:

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

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

In Node

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

<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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.