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-on-image

v1.0.2

Published

A general image watermark library for web

Downloads

8

Readme

watermark-on-image

This is a general image watermark library for web browser, which supports marking both texts and images repeatedly covering the image in the form of a chaining calling.

Installing

npm install watermark-on-image

Usage

Using the chaining calling to load source images, mark images or texts, and other related options. It supports receiving url paths and Image objects.

// Mark Image
new WaterMarkkk()
.loadSrc('src/1.png')
.markImage('mark/1.png')
.markSpacing(600, 200)
.getImage('png', 1.0, { width: 1500, height: 800 })
.then(imgs => {
    const imgElement = document.createElement('img');
    imgElement.src = imgs[0];
    document.getElementById('root').appendChild(imgElement);
});

// Mark Texts
new WaterMarkkk()
.loadSrc(['src/1.png', 'src/2.png'])
.markText(['mark1', 'mark2'])
.markSpacing(100, 100)
.markOpicity(0.6)
.markRotation('40deg')
.getImage('jpeg', 1.0)
.then(imgs => {
    imgs.forEach(img => {
        const imgElement = document.createElement('img');
        imgElement.src = img;
        document.getElementById('root').appendChild(imgElement);
    })
});

Method

  • loadSrc

    Recieve single path, Image object or the array of them. Each image in the array will be processed by the same configuration.

    loadSrc(src: string | HTMLImageElement | (string | HTMLImageElement)[])
  • markImage

    Same with loadSrc method

    markImage(mark: string | HTMLImageElement | (string | HTMLImageElement)[])
  • markText

    Recieve a single string or the array of strings to mark. All the texts will be ordered repeatedly to cover the whole image. You can also set related options for texts.

    markText(mark: string | string[], textOptions?: {
        color?: string,
        font?: string
    })    

    Default:

    • mark: 'WaterMarkkk'
    • color: 'black'
    • font: 'bold 24px serif'
  • markRotation

    Set for the rotation angle (0 degree - 180 degree) of mark. Recieve number (ie. Math.PI) or string (ie. "30 deg"). Here the number must be in the unit degree (Math.PI).

    markRotation: (rotation: number | string);

    Default: 0

  • markOpicity

    Set the mark opicity (0 - 1).

    markOpicity: (opicity: number)

    Default: 1.0

  • markSpacing

    Set markers' vertical and horizontal spacing distance (in the unit of px). Recieve string (ie. "30 px") or number (ie. 30).

    markSpacing: (vertical: string | number, horizontal: string | number);

    Default:

    • vertical: 20
    • horizontal: 20
  • getImage

    Must be called to get marked img result. It will return a list of img based on the format you choose. It provides four options: 'jpeg', 'png', 'webp' and 'canvas'. Here 'canvas' refers to the HTMLCanvasElement. Except for canvas, all the other forms of image will be returned as URI string. It also provides quality (0 - 1) and size options.

    getImage: (type?: ExportType, quality?: number, size?: {
        width?: number;
        height?: number;
    }) => Promise<string[] | HTMLCanvasElement[]>;

    Default:

    • type: png
    • quality: 1.0
    • size: undefined (which means keeping the same with the original image)

Start & Building

Generate a template with html page into dist folder based on the file from test/example. You can test functionalities by this.

npm run start

Build for publish

npm run build

Test

Use jest to test some basic utility functions. You can find them in the test folder.

npm run test

Suggestions

Please feel free to make suggestions and contributions.