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

watermark-helper

v1.0.0

Published

A helper class for adding watermarks to images

Downloads

2

Readme

WatermarkHelper 使用文档

WatermarkHelper 是一个用于在 Canvas 上添加图像和文字水印的辅助类。

安装

首先确保已经安装了 watermark-helper 包:

npm install watermark-helper

或者使用 yarn:

yarn add watermark-helper

引入

在您的项目中引入 WatermarkHelper

import WatermarkHelper from 'watermark-helper';

使用方法

参数

watermarkGenerator 方法接受一个配置对象作为参数,配置对象包含两个主要部分:sourcewatermark

  • source 对象包含源图像的信息:

    • url (string): 源图像的 URL。
    • width (number, optional): 源图像的宽度。
    • height (number, optional): 源图像的高度。
  • watermark 对象包含水印的信息:

    • text (string, optional): 要添加的文字水印内容。
    • color (string, optional): 文字水印的颜色。
    • url (string, optional): 要添加的图像水印的 URL。
    • width (number, optional): 图像水印的宽度。
    • height (number, optional): 图像水印的高度。
返回值

watermarkGenerator 方法返回一个 Promise,Promise 的解析值是生成的带水印的图像数据 URL。

示例

以下示例展示了如何使用 watermarkGenerator 方法:

import WatermarkHelper from 'watermark-helper';

const helper = new WatermarkHelper();

// 配置对象,包含源图像和水印信息
const config = {
  source: {
    url: 'path/to/your/source-image.jpg',
    width: 800, // 可选,源图像宽度
    height: 600, // 可选,源图像高度
  },
  watermark: {
    text: 'Confidential',
    color: '#ff0000', // 可选,文字颜色
    // url: 'path/to/your/watermark-image.png', // 可选,图像水印的 URL
    // width: 200, // 可选,图像水印的宽度
    // height: 100, // 可选,图像水印的高度
  },
};

// 调用 watermarkGenerator 方法生成带水印的图像数据 URL
helper.watermarkGenerator(config)
  .then(dataUrl => {
    // dataUrl 包含了带水印的图像数据 URL,可以将其用作需要显示水印的地方
    const imgElement = new Image();
    imgElement.src = dataUrl;
    document.body.appendChild(imgElement);
  })
  .catch(error => {
    console.error('Failed to generate watermark:', error);
  });

注意事项

  • 确保配置对象中提供了源图像的 URL (source.url),以及至少一个水印(文字或图像)的信息 (watermark.textwatermark.url)。
  • 如果需要,可以根据实际需求调整 watermarkGenerator 方法的配置对象,例如指定水印的颜色、位置和大小等。