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-watermark

v0.0.7

Published

A powerful watermark library for image and pdf files based on ImageMagick for node.js

Downloads

1,538

Readme

image-watermark

A powerful watermark library based on ImageMagick for node.js. This can be used to embed watermark in single page image, multipage image or pdf file.

Installation

'npm install image-watermark'

Server-side usage

var watermark = require('image-watermark');

watermark.embedWatermark('/path/to/image_or_pdf/file', [options]);

Clone the repo

git clone https://github.com/luthraG/image-watermark.git

API

embedWatermark(source, [options])

API to embed watermark in given image/pdf. It takes two arguments :

  1. path of the image and
  2. options object. This argument is optional

Options

Various options supported by this API are :

  • text - To specify watermark text. Default is 'Sample watermark'.
  • color - To specify color of watermark text. Default is 'Grey'.
  • dstPath - To specify the output path. Default is 'watermark.{sourceFile ext}'.
  • override-image - To specify if same image needs to be overriden. Default is 'false'.
  • change-format - To specify if the format of output file needs to be changed. Default is 'false'.
  • output-format - Used in conjuction with change-format to specify the format of output file.
  • align - To specify the watermark text alignment. Default is 'dia1'.
  • font - To specify font of watermark text.
  • resize - To specify the resize percentage for output file.

Example

var watermark = require('image-watermark');

watermark.embedWatermark('\home\user\sample.jpg', {'text' : 'sample watermark'});

Different Options

//
// Options with watermark text, if not provided defaults to 'Sample watermark'
//
var watermark = require('image-watermark');
watermark.embedWatermark('\home\user\sample.jpg', {'text' : 'sample watermark'});

//
// Options to specify output path
//
var watermark = require('image-watermark');
var options = {
	'text' : 'sample watermark', 
	'dstPath' : '\home\user\documents\watermark.jpg'
};
watermark.embedWatermark('\home\user\sample.jpg', options);

//
// Options to specify color of watermark text
//
var watermark = require('image-watermark');
var options = {
	'text' : 'sample watermark', 
	'color' : 'rgb(154, 50, 46)'
};
watermark.embedWatermark('\home\user\sample.jpg', options);

// color can be specified in one of the following forms
grey					  #color-name
#f00                      #rgb
#ff0000                   #rrggbb
#ff0000ff                 #rrggbbaa
#ffff00000000             #rrrrggggbbbb
#ffff00000000ffff         #rrrrggggbbbbaaaa
rgb(255, 0, 0)            an integer in the range 0—255 for each component
rgb(100.0%, 0.0%, 0.0%)   a float in the range 0—100% for each component


//
// Options to specify resize factor i.e. if image needs to be resized
// after adding watermark text
//
var watermark = require('image-watermark');
var options = {
	'text' : 'sample watermark', 
	'resize' : '200%'
};
watermark.embedWatermark('\home\user\sample.jpg', options);


//
// Options to override same image i.e. if same image needs to
// be overriden after adding watermark, By default is false
//
var watermark = require('image-watermark');
var options = {
	'text' : 'sample watermark', 
	'override-image' : true
};
watermark.embedWatermark('\home\user\sample.jpg', options);

// This overrides the same image, if not specified it creates
// output image parallel to this image with name "watermark"

//
// Options to change the format of image
//
var watermark = require('image-watermark');
var options = {
	'text' 			: 'sample watermark', 
	'change-format' : true,
	'output-format' : 'bmp'
};
watermark.embedWatermark('\home\user\sample.jpg', options);

//
// Options to specify the font of watermark text
//
var watermark = require('image-watermark');
var options = {
	'text' : 'sample watermark', 
	'font' : 'Arial.ttf'
};
watermark.embedWatermark('\home\user\sample.jpg', options);

//
// Options to specify the alignment of watermark text
//
var watermark = require('image-watermark');
var options = {
	'text' : 'sample watermark', 
	'align' : 'ltr'
};
watermark.embedWatermark('\home\user\sample.jpg', options);

// Various possble values of align are:

//
// dia1 : Diagonal 1
// dia2 : Diagonal 2
// ttb : top to bottom
// btt : bottom to top
// ltr : left to right
// rtl : right to left
//

// If an invalid value is specified or in case no value
// is specified then 'dial1' is treated as default alignment

embedWatermarkWithCb(source, [options], callback)

API to embed watermark in given image/pdf with callback method. It takes three arguments :

  1. path of the image and
  2. options object. This argument is optional
  3. The callback method

// Embed watermark with option object and callback method
var watermark = require('image-watermark');
var option = {'text' : 'sample watermark'};

watermark.embedWatermarkWithCb('\home\user\sample.jpg', option, function(err) {
	if (!err)
		console.log('Succefully embeded watermark');
});

// Embed watermark with no option object and callback method
var watermark = require('image-watermark');

watermark.embedWatermarkWithCb('\home\user\sample.jpg', function(err) {
	if (!err)
		console.log('Succefully embeded watermark');
});

version

API to get version of this module that you are using.

var watermark = require('image-watermark');

watermark.version;

// It outputs version of the API.

Inspiration

https://www.npmjs.com/package/imagemagick

License(MIT)

Copyright (c) 2015 Gaurav Luthra([email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.