GithubHelp home page GithubHelp logo

vincent7128 / text-image Goto Github PK

View Code? Open in Web Editor NEW
74.0 2.0 15.0 172 KB

Convert text to image https://vincent7128.github.io/text-image/

License: MIT License

JavaScript 100.00%
html5 canvas text image

text-image's Introduction

Text Image

About

๐Ÿ“บ Live Demo
Convert text to image. Work with unicode and web font like FontAwesome, you can use emoji too. ๐Ÿš€

Usage

NPM:

npm install text-image

CDN:

<script src="https://cdn.jsdelivr.net/npm/text-image/dist/text-image.js"></script>

Code example:

// create new TextImage object
var textImage1 = TextImage();

// create new TextImage object with customize style
var style = {
    font: 'serif',
    align: 'center',
    color: 'red',
    size: 18,
    background: 'white',
    stroke: 1,
    strokeColor: 'rgba(0, 0, 0, 0)',
    lineHeight: '1.6em',
    bold: true,
    italic: true
};
var textImage2 = TextImage(style);

// convert text message to image element
var img = textImage.toImage('MESSAGE');

// convert text message to base64 dataURL
var data = textImage.toDataURL(message);

// change style
textImage.setStyle(style);

Style object

The default style object

{
    font: 'Sans-serif',
    align: 'left',
    color: '#000000',
    size: 16,
    background: 'rgba(0, 0, 0, 1)',
    stroke: 0,
    strokeColor: '#FFFFFF',
    lineHeight: '1.2em'
}

font

The font property like css font-family and you can use web fonts like FontAwesome.

align

The align property specifies the horizontal alignment of text, use 'left', 'center' or 'right'.

color & background & strokeColor

The color, background and strokeColor property like css color.

/* <named-color> values */
color: 'red'
color: 'orange'
color: 'tan'
color: 'rebeccapurple'

/* <hex-color> values */
color: '#090'
color: '#009900'
color: '#090a'
color: '#009900aa'

/* <rgb()> values */
color: 'rgb(34, 12, 64, 0.6)'
color: 'rgba(34, 12, 64, 0.6)'
color: 'rgb(34 12 64 / 0.6)'
color: 'rgba(34 12 64 / 0.3)'

/* <hsl()> values */
color: 'hsl(30, 100%, 50%, 0.6)'
color: 'hsla(30, 100%, 50%, 0.6)'
color: 'hsl(30 100% 50% / 0.6)'
color: 'hsla(30 100% 50% / 0.6)'

size & stroke

The size and stroke property is the text size and outline width, only use numbers.

lineHeight

The lineHeight property like css line-height.

License

This project is licensed under the MIT License - see the LICENSE file for details

text-image's People

Contributors

anuj9196 avatar dependabot[bot] avatar vincent7128 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

text-image's Issues

Package.json main points to non-existent file

The main property of the package.json file is pointing to dist/text-image.min.js, but the actual file is dist/text-image.js.

This is causing the module not to be loaded properly when using require() statements.

own text style (help)

Hi thank you for a great project, could you advise me how I can add my own fonts when I have downloaded .TTF files? Thank you

I try to use a font that the machine will not be able to read (eg facebook, google)

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.