0.5.3 • Published 7 months ago

sharp-watermark v0.5.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

sharp-watermark

npm type definitions npm npm

Installation

npm install sharp-watermark

Usage

Add an image watermark:

import { addImageWatermark } from "sharp-watermark";

const watermarkedImage = await addImageWatermark(
  "path/mainImage.jpg", // or a buffer
  "path/watermark.jpg", // or a buffer
  options
);

Add a text watermark:

import { addTextWatermark } from "sharp-watermark";

const watermarkedImage = await addTextWatermark(
  "path/mainImage.jpg", // or a buffer
  "Hello World!",
  options
);

Parameters

  • mainImage (required): The main image to which the watermark will be added. It can be either a string path or a buffer representing the image.
  • watermarkImage (required for image watermarks): The watermark image to be added to the main image. It can be either a string path or a buffer representing the image.
  • watermarkText (required for text watermarks): The text to be used as the watermark.
  • options (optional): an object containing the options for the watermarking process. See the Options section for more details.

Access the watermarked image:

// you can save it to a file
watermarkedImage.toFile("watermarkedImage.png");

// or you can convert it to a buffer
const buffer = await watermarkedImage.toBuffer();

Options

The options parameter is an object that contains the following properties:

  • ratio (default: 0.4): the ratio of the watermark image to the main image.
  • dpi (default: 300): Size of the text. Only applicable for text watermarking.
  • opacity (default: 0.6): the opacity of the watermark text. Only applicable for text watermarking.
  • position (default: center): the position of the watermark image. Can be one of the following: topLeft, top, topRight, left, center, right, bottomLeft, bottom, bottomRight. Ignored if both x & y property is passed.
  • x (default: undefined): the x coordinate of the watermark image.
  • y (default: undefined): the y coordinate of the watermark image.

Special Thanks

  • sharp - The image processing library used in this project.
  • jimp-watermark - The inspiration for this project. Reasons to use this package over jimp-watermark:
    • Less file size.
    • Support for watermark positioning.
    • built in type definitions.
0.5.3

7 months ago

0.5.2

1 year ago

0.5.1

1 year ago

0.5.0

1 year ago

0.4.0

1 year ago

0.3.5

1 year ago

0.3.4

1 year ago

0.3.3

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago