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 🙏

© 2025 – Pkg Stats / Ryan Hefner

images-watermark

v0.0.6

Published

A simple and customizable Node.js library for adding text or image watermarks to images, supporting various styling options and configurations.

Downloads

1,467

Readme

Images Watermark

images-watermark is a Node.js library that uses the Sharp library to add watermarks (text or logos) to images. The tool allows you to watermark images to protect or brand your content. You can apply text watermarks, logo watermarks, or a combination of both.

npm version License

Features

  • Text Watermark: Add custom text as a watermark to images.
  • Image Logo Watermark: Overlay an image logo as a watermark.
  • Combined Watermarks: Apply both text and image watermarks on the same image.

Installation

You can install the library using npm:

  npm install images-watermark

Watermarking an Image Using singleImageWatermark

This guide demonstrates how to add a watermark to an image using the singleImageWatermark library. This is useful for branding or protecting your images.

Code Example

const { singleImageWatermark } = require('images-watermark');
const path = require('path');

const imagesWatermark = async function (req, res) {
    try {
        const watermarkedImage = await singleImageWatermark({
            // Path to the image you want to watermark
            imagePath: path.join(__dirname, '../../../public/images/image.jpg'), 

            // Path to the watermark image (e.g., logo or watermark text)
            watermarkPath: path.join(__dirname, '../../../public/images/Watermark.png'), 

            // Allowed referrers for cross-origin resource sharing (CORS)
            allowedReferrers: ['http://localhost:3000'], 

            // Custom headers to mimic the request context
            headers: {
                host: 'localhost:3000', // Specify the host for the request
                connection: 'keep-alive', // Keep the connection open for further requests
                'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
                // Include the User-Agent header to emulate the client browser
            },
        });

        // Set the response content type and send the watermarked image
        res.setHeader('Content-Type', 'image/png');
        return res.send(watermarkedImage);
    } catch (error) {
        console.error('Error generating watermarked image:', error);
        res.status(500).send('An error occurred while processing the image.');
    }
};

Parameters

| Parameter | Type | Mandatory | Description | |-------------------|------------|------------|-----------------------------------------------------------------------------| | imagePath | string | Required | The path to the original image. | | headers | object | Required | Headers for API calls, e.g., request headers. | | allowedReferrers| array | Required | List of allowed domains for cross-platform access (CORS). | | watermarkPath | string | Optional | The path to the watermark image (e.g., a logo). | | textWatermark | string | Optional | Text to use as a watermark. | | appName | string | Optional | The application name (for branding purposes). | | textColor | string | Optional | Color of the watermark text, e.g., #000000. | | opacity | string | Optional | Opacity of the watermark text, e.g., 0.3. | | fontWeight | string | Optional | Font weight of the watermark text, e.g., 800. | | textLineSpacing | int | Optional | Line spacing for the text watermark. | | fontFamily | string | Optional | Font family for the text watermark, e.g., Inter, Arial, sans-serif. |

Watermarking Multiple Images Using multiImageWatermark

This guide demonstrates how to add a watermark to multiple images using the multiImageWatermark library. This is useful for branding or protecting your images.

Code Example

const { multiImageWatermark } = require('images-watermark');
const path = require('path');

const imagesWatermark = async function (req, res) {
    try {
        const watermarkedImages = await multiImageWatermark({
            // Path to the images you want to watermark
            imagePaths: [path.join(__dirname, '../../../public/images/image1.jpg'), path.join(__dirname, '../../../public/images/image2.jpg')], 

            // Path to the watermark image (e.g., logo or watermark text)
            watermarkPath: path.join(__dirname, '../../../public/images/Watermark.png'), 

            // Allowed referrers for cross-origin resource sharing (CORS)
            allowedReferrers: ['http://localhost:3000'], 

            // Custom headers to mimic the request context
            headers: {
                host: 'localhost:3000', // Specify the host for the request
                connection: 'keep-alive', // Keep the connection open for further requests
                'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
                // Include the User-Agent header to emulate the client browser
            },
        });

        return res.send(watermarkedImages);
    } catch (error) {
        console.error('Error generating watermarked image:', error);
        res.status(500).send('An error occurred while processing the image.');
    }
};

Parameters

| Parameter | Type | Mandatory | Description | |-------------------|------------|------------|-----------------------------------------------------------------------------| | imagePaths | array | Required | In array, push paths to the original images. | | headers | object | Required | Headers for API calls, e.g., request headers. | | allowedReferrers| array | Required | List of allowed domains for cross-platform access (CORS). | | watermarkPath | string | Optional | The path to the watermark image (e.g., a logo). | | textWatermark | string | Optional | Text to use as a watermark. | | appName | string | Optional | The application name (for branding purposes). | | textColor | string | Optional | Color of the watermark text, e.g., #000000. | | opacity | string | Optional | Opacity of the watermark text, e.g., 0.3. | | fontWeight | string | Optional | Font weight of the watermark text, e.g., 800. | | textLineSpacing | int | Optional | Line spacing for the text watermark. | | fontFamily | string | Optional | Font family for the text watermark, e.g., Inter, Arial, sans-serif. |

Example Usage

This implementation watermarks an image (or multiple images) with a logo or text and allows customization of the watermark's appearance. It also ensures proper CORS handling for cross-domain requests.

🔗 Auther Details

portfolio linkedin