npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

text-behind-image

v1.2.0

Published

Text-Behind-Image: A framework-agnostic npm package for applying the text-behind-image effect in web apps, compatible with React, Vue, Svelte and other modern frameworks. Inspired by the work of Rexan Wong.

Downloads

3

Readme

Text-behind-image package

A framework-agnostic package to display the text-behind-image effect in any web application or Node.js script. Inspired by the work of Rexan Wong and developed to be easily integrated directly into your projects.


Installation

npm install text-behind-image

Usage

This package provides a single core function, TextBehindImage, which takes an image (URL, File, or Blob), advanced text settings (single or multiple layers), and a result image format/output type to apply the text-behind-image effect.

Framework-agnostic: Works in any environment that supports the HTML Canvas API (browsers, Electron, Node.js with canvas).

Basic Example

import { TextBehindImage } from "text-behind-image";

const result = await TextBehindImage({
  image: fileOrUrl, // string | File | Blob
  textSettings: [
    {
      font: "Arial",
      fontSize: 48,
      color: "white",
      content: "Sample Text",
      position: { x: 100, y: 100 },
      alignment: "center",
      rotation: 0,
      shadowColor: "#000",
      shadowBlur: 10,
      shadowOffsetX: 0,
      shadowOffsetY: 0,
      strokeColor: "#fff",
      strokeWidth: 2,
      opacity: 0.9,
      letterSpacing: 2,
      lineHeight: 1.5,
    },
    // ...more layers
  ],
  format: "png",
  outputType: "dataUrl", // or 'blob' | 'file'
  bgRemovalOptions: { /* options for background removal */ },
});

Usage in Frameworks

React

import React, { useState } from "react";
import { TextBehindImage } from "text-behind-image";

const App = () => {
  const [imageUrl, setImageUrl] = useState("");
  const generateImage = async () => {
    const result = await TextBehindImage({
      image: "https://example.com/image.png",
      textSettings: {
        font: "Arial",
        fontSize: 48,
        color: "white",
        content: "Sample Text",
        position: { x: 100, y: 100 },
      },
      format: "png",
    });
    setImageUrl(result);
  };
  return (
    <div>
      <button onClick={generateImage}>Generate Image</button>
      {imageUrl && <img src={imageUrl} alt="Generated" />}
    </div>
  );
};

Vue 3

<template>
  <div>
    <button @click="processImage">Generate Image</button>
    <img v-if="imageUrl" :src="imageUrl" alt="Generated" />
  </div>
</template>
<script setup>
import { ref } from 'vue';
import { TextBehindImage } from 'text-behind-image';
const imageUrl = ref('');
async function processImage() {
  const result = await TextBehindImage({
    image: 'https://example.com/image.png',
    textSettings: {
      font: 'Arial',
      fontSize: 48,
      color: 'white',
      content: 'Sample Text',
      position: { x: 100, y: 100 },
    },
    format: 'png',
  });
  imageUrl.value = result;
}
</script>

Svelte

<script>
  import { TextBehindImage } from 'text-behind-image';
  let imageUrl = '';
  async function generateImage() {
    const result = await TextBehindImage({
      image: 'https://example.com/image.png',
      textSettings: {
        font: 'Arial',
        fontSize: 48,
        color: 'white',
        content: 'Sample Text',
        position: { x: 100, y: 100 },
      },
      format: 'png',
    });
    imageUrl = result;
  }
</script>
<button on:click={generateImage}>Generate Image</button>
{#if imageUrl}
  <img src={imageUrl} alt="Generated" />
{/if}

API Reference

TextBehindImage

Processes an image by applying a text-behind-image effect.

Parameters

  • image (string | File | Blob): The image to process (URL, File, or Blob).
  • textSettings (object | object[]): Settings for one or more text layers. Each object supports:
    • font (string): Font family
    • fontSize (number): Font size
    • color (string): Text color
    • content (string): Text content
    • position (object): { x: number, y: number }
    • alignment (CanvasTextAlign): Text alignment
    • rotation (number): Rotation in degrees
    • shadowColor, shadowBlur, shadowOffsetX, shadowOffsetY
    • strokeColor, strokeWidth
    • opacity (number): 0-1
    • letterSpacing (number)
    • lineHeight (number)
  • format (string): Output format ('png', 'jpg', 'webp')
  • outputType (string): 'dataUrl' (default), 'blob', or 'file'
  • bgRemovalOptions (object): Options for background removal (see @imgly/background-removal)

Returns

  • A Promise<string | Blob | File>: The final image as a Data URL, Blob, or File.

Browser & Node.js Support

  • Browser: Works in all modern browsers with Canvas support. For background removal, your site must be cross-origin isolated (see MDN).
  • Node.js: Works with Node.js v14+ and the canvas package. See system dependencies below.

Requirements

Node.js

  • Version: Node.js v14.0.0 or higher is recommended for compatibility with ES modules and the canvas package.

Additional Libraries

System Dependencies

  • Linux:
    sudo apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev
  • MacOS:
    brew install pkg-config cairo pango libpng jpeg giflib librsvg
  • Windows: Install Windows Build Tools and libraries required for canvas. Refer to the canvas installation guide for detailed instructions.

Contribute

If you want to contribute to this project, feel free to open an issue or fork this repository & open a pull request. Please:

  • Test all changes you make to ensure the functionality remains intact.
  • Follow the existing code style and structure where possible.
  • Document your changes, including examples when applicable.

We appreciate all contributions that help make this package better!

Again, a big thanks to Rexan Wong for his incredible original work on the text-behind-image website, which inspired this package.