Skip to content

Repository files navigation

text-to-png

A CLI tool that renders text to a PNG image. Provide your text, pick a color, font, and size — the tool renders a PNG, opens it in your system image viewer for review, and then lets you save it, redraw with new options, or quit.


Installation

npm install

To use the text-to-png command globally from anywhere on your machine:

npm link

To unlink later: npm unlink -g text-to-png-renderer


Usage

npm run cli -- --text "Your text here" [options]

# or, after npm link:
text-to-png --text "Your text here" [options]

Options

Flag Short Description Default
--text -t Text to render (required)
--color -c Text color — hex or CSS named color black
--size -s Font size in pixels (8–500) 32
--font -f Font preset or path to a .ttf/.otf file sans

Font presets

Preset Typeface
sans Roboto Regular
bold Roboto Bold
mono Roboto Mono Regular

Examples

# Basic
npm run cli -- --text "Hello World"

# Custom color (named) and size
npm run cli -- --text "Launch Day" --color tomato --size 64

# Hex color and bold font
npm run cli -- --text "Big News" --color "#3b82f6" --size 48 --font bold

# Monospace font
npm run cli -- --text "console.log('hi')" --font mono --size 24

# Custom font file
npm run cli -- --text "Custom Font" --font ./path/to/MyFont.ttf --color purple

How it works

You run the command with --text, --color, --size, --font
              │
              ▼
        Validate inputs
    (color format, size range,
      font preset or file path)
              │
              ▼
       Render PNG in memory
    (auto-sized canvas, white
     background, text centered)
              │
              ▼
    Open preview in system
       image viewer
              │
              ▼
    ┌─────────────────────┐
    │  Interactive prompt  │
    └─────────────────────┘
         │    │    │
       save  redraw quit
         │    │    │
         │    │    └── Delete temp file → Exit
         │    │
         │    └── Re-prompt options (with current
         │        values as defaults) → Re-render
         │        → Update preview → Loop
         │
         └── Ask for filename → Write PNG → Loop

Interactive commands

Once the preview opens, you'll see this prompt in your terminal:

? What would you like to do? (Use arrow keys)
❯ save    — save the PNG to a file
  redraw  — change options and regenerate
  quit    — exit without saving
Command What it does
save Prompts for a filename (default: output.png). Writes the PNG to that path. Returns to the prompt so you can save again or continue.
redraw Re-prompts for text, color, size, and font — with your current values pre-filled as defaults. Press Enter to keep any value unchanged. Re-renders and updates the preview.
quit Deletes the temporary preview file from your system's temp directory and exits the tool cleanly. Any unsaved images are lost.

What happens when you quit

  • The temporary preview file (/tmp/text-to-png-preview.png on macOS/Linux) is deleted automatically.
  • Any PNG you already saved with save remains on disk — quitting does not remove those.
  • If you force-quit (Ctrl+C), the temp file may remain in /tmp/ until your OS clears it.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages