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

watertext

v1.1.0

Published

Vanilla JavaScript image watermarking with text

Downloads

38

Readme

Watertext - text watermarking library

CircleCI API Doc

Features

  • Zero dependencies library, works with NodeJS and in the browser.
  • 1.7kb minified (481B gzipped) version.

Quickstart

  1. Install library:
npm install --save watertext
  1. Watermark regular image with awesome text:
var el = document.getElementsByTagName('img')[0];

// Version 1: callback based (watertext.core.umd.min.js)
watertext(el.src, {text: 'Awesome cat'}, function(err, src){
  el.src = src;
});
// Version 2: promise based (watertext.umd.min.js)
watertext(el.src, {text: 'Awesome cat'})
  .then(function(url){el.src = url;});

| Original image | Watermarked image | |:---:|:---:| | orig-image | watermarked-image |

Versions

There are two main versions:

  1. Callback-based vanilla js core.
  2. Promise-based (via core-js polyfill) regular.

Depending on usage, there are 3 build options: CommonJS, ES6 module and UMD library. All build are handled by rollup. Backend specific versions (CommonJS and ES6 module) are not minified (~5 Kb) and browser specific UMD comes in minified version only (~1.7 Kb).

| Name | CommonJS | ES6 module | UMD | |---|---|---|---| | Core (Callback based) | watertext.core.cjs.js | watertext.core.esm.js | watertext.core.umd.min.js | | Regular (Promise based) | watertext.cjs.js | watertext.esm.js | watertext.umd.min.js |

Development

The library is tiny and the whole source code is in index.js file. It uses ES6 syntax with AirBnB style-guide. Make sure to eslint your code and write jsdoc for every method.

Supported Browsers
npx browserslist

Deployment

Webpack builds both regular and minified versions to dist folder. It uses rollup + bublé because they are faster than webpack + buble and result into smaller build size (~30% reduction).

yarn build

Publish new version with yarn:

yarn publish

Watermarking options

All of the parameters except text are optional. By default, the watermark is placed at the bottom of the image with 10px margin.

| Name | Type | Default | Description | |---|---|---|---| | text | string | '' | Watermark text. | | textWidth | number | undefined | Width of watermark in pixels. By default watermark uses 100% of the image width if positioned at the top/bottom and 100% of hight if positioned on the left/right. | | textSize | number | 12 | Watermark text size. | | textFont | string | 'Sans-serif' | Watermark text font. | | textColor | string | 'rgb(255, 255, 255)' | Watermark text color. | | backgroundColor | string | 'rgba(0, 0, 0, 0.4)' | Watermark background color. Default is gray. | | position | string | 'bottom' | Position of watermark text, one of "top", "left", "right" or "bottom". | | margin | number | 10 | Margin from the nearest edge. Negative margin positions watermark at the opposite edge. Useful for text orientation control for "left" and "right" positioning. | | dataURL | Array | [] | Parameters of canvas.toDataURL(type, encoderOptions). Default format type is image/png. Example options: ["image/jpeg", 0.5] or ["image/webp", 0.6]. |

Links

Acknowledgement

  • baivong/watermark library hugely inspired this project. While there are a lot of similarities, this library does not require jQuery to watermark images.
  • brianium/watermarkjs good multi-purpose watermarking library, inspired ES6 adoption and Webpack usage.
  • Cat image is provided by pexels.