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 🙏

© 2024 – Pkg Stats / Ryan Hefner

image-video-watermark

v1.0.1

Published

Library to add watermark to images and videos using Node.js with Jimp and ffmpeg.

Downloads

4

Readme

image-video-watermark

This module allows you to add watermarks to images or videos using Node.js.

Installation

Make sure you have Node.js installed (version 10 or above) and FFmpeg installed on your system.

npm install image-video-watermark

Or

yarn add image-video-watermark

Usage

import addWatermark from 'image-video-watermark';

// Path to the original file
const inputPath = './path/to/input/file';

// Path to the watermark image
const watermarkPath = './path/to/watermark/image.png';

// Optional options
const options = {
  position: 'bottom-right', // Watermark position ('top-right', 'bottom-right', 'top-left', 'bottom-left')
  margin: 20, // Margin between watermark and video/image edge (default is 10)
  opacity: 0.7, // Opacity of the watermark (value between 0 and 1, default is 0.5)
  watermarkScalePercentage: 15 // Percentage scale of the watermark (default is 10)
};

// Adding watermark to image or video
(async () => {
  try {
    const result = await addWatermark(inputPath, watermarkPath, options);
    console.log('Watermark added successfully:', result);
  } catch (error) {
    console.error('Error adding watermark:', error);
  }
})();

System Requirements

  • Node.js 10 or above.
  • FFmpeg installed on your system.

Example with Telegraf

import { Telegraf } from 'telegraf';
import addWatermark from 'image-video-watermark';

const bot = new Telegraf('YOUR_BOT_TOKEN');

bot.on('document', async (ctx) => {
  const fileId = ctx.message.document.file_id;
  const watermarkPath = './path/to/watermark/image.png';

  try {
    const file = await ctx.telegram.getFile(fileId);
    const inputPath = `https://api.telegram.org/file/bot${bot.token}/${file.file_path}`;

    const options = {
      position: 'bottom-right',
      margin: 20,
      opacity: 0.7,
      watermarkScalePercentage: 15
    };

    const result = await addWatermark(inputPath, watermarkPath, options);
    console.log('Watermark added to Telegram file:', result);

    // Send the watermarked file back to user
    await ctx.replyWithDocument({ source: result.buffer });
  } catch (error) {
    console.error('Error processing Telegram file:', error);
  }
});

bot.launch();

Example with Express

import express from 'express';
import multer from 'multer';
import addWatermark from 'image-video-watermark';

const app = express();
const upload = multer({ dest: 'uploads/' });

app.post('/upload', upload.single('file'), async (req, res) => {
  const inputPath = req.file.path;
  const watermarkPath = './path/to/watermark/image.png';

  try {
    const options = {
      position: 'bottom-right',
      margin: 20,
      opacity: 0.7,
      watermarkScalePercentage: 15
    };

    const result = await addWatermark(inputPath, watermarkPath, options);
    console.log('Watermark added to uploaded file:', result);

    res.set('Content-Type', 'image/jpeg');
    res.send(result.buffer);
  } catch (error) {
    console.error('Error processing uploaded file:', error);
    res.status(500).send('Error processing file');
  }
});

app.listen(3000, () => {
  console.log('Server is running on http://localhost:3000');
});

Contributing

If you would like to contribute to this project, please fork the repository and open a pull request.

Support

If you encounter any issues or have questions, please open an issue on GitHub issues.

License

This project is licensed under the MIT License.


Make sure to replace './path/to/input/file' and './path/to/watermark/image.png' with actual paths to your input file and watermark image respectively.