Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

image-video-watermark

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-video-watermark

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

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
0
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 24 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc