• This repository has been archived on 29/Sep/2020
  • Stars
    star
    1,707
  • Rank 27,339 (Top 0.6 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 9 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🎑 Watermarking for the browser

watermark.js Build Status

A functional library for watermarking images in the browser. Written with ES6, and made available to current browsers via Babel. Supports urls, file inputs, blobs, and on-page images.

Note: For anyone that is interested: I ported this to a ClojureScript library called Dandy Roll.

Tested Browsers

Any browser supporting File and FileReader should work. The following browsers have been tested and work:

  • IE10 (Windows 7)
  • Chrome 42 (OS X 10.10.3)
  • Firefox 38 (OS X 10.10.3)
  • Safari 8.0.6 (OS X 10.10.3)
  • Opera 29.0 (OS X 10.10.3)

Please feel free to update this list or submit a fix for a particular browser via a pull request.

Installing

watermark.js is available via npm and bower:

# install via npm
$ npm install watermarkjs

# install via bower
$ bower install watermarkjs

Usage

// watermark by local path
watermark(['img/photo.jpg', 'img/logo.png'])
  .image(watermark.image.lowerRight(0.5))
  .then(img => document.getElementById('container').appendChild(img));

// load a url and file object
const upload = document.querySelector('input[type=file]').files[0];
watermark([upload, 'img/logo.png'])
  .image(watermark.image.lowerLeft(0.5))
  .then(img => document.getElementById('container').appendChild(img));

// watermark from remote source
const options = {
  init(img) {
    img.crossOrigin = 'anonymous'
  }
};
watermark(['http://host.com/photo.jpg', 'http://host.com/logo.png'], options)
  .image(watermark.image.lowerRight(0.5))
  .then(img => document.getElementById('container').appendChild(img));

Building

Before building or testing, install all the deps:

npm i

There is an npm script you can run to build:

npm run build

Or to kick off the file watcher and build as you make changes, run the start task:

$ npm start

Testing

There is an npm script for that too!:

$ npm test

This library uses the Jest testing framework. Due to some current issues with Jest, Node 0.10.x is required to run the tests.

Examples

You can view examples and documentation by running the sync task via npm:

$ npm run sync

The examples demonstrate using watermark images and text, as well as a demonstration of uploading a watermarked image to Amazon S3. It is the same content hosted at http://brianium.github.io/watermarkjs/.

Development

Running npm run dev will start a browser and start watching source files for changes.

Motivation

  • Not every server has image libraries (shared hosting anyone?)
  • Not every server has reliable concurrency libs for efficient uploading (shared hosting anyone?)
  • JavaScript is fun and cool - more so with ES6

Clearly watermarking on the client has some limitations when watermarking urls and on-page elements. The curious can find urls for non-watermarked images, but it is likely that most average users won't go down this path - keeping this soft barrier useful. However!...

watermark.js has the ability to accept file inputs as a source for watermarking. This makes it easy to preview, watermark, and upload without the non-watermarked image ever becoming public. Check out the uploading demo to see this in action.

This tool certainly shines in admin or CMS environments where you want to generate watermarks and upload them asynchronously where it would not be possible or preferable on the server. One less thing the server has to do can be a good thing :)

Suggestions? Improvements?

Please open issues or pull requests if you have bugs/improvements.

More Repositories

1

clean-todos

📋 A todo example leveraging clean architecture in Clojure
Clojure
82
star
2

tomaat

🍅 Slack integrated pomodoro timer... with Electron + ClojureScript!
Clojure
60
star
3

tdd-ddd-php

A Test Driven example of Domain Driven Design in PHP
PHP
55
star
4

habitat

Dependable environment variables for PHP
PHP
44
star
5

patroclus

👬 Is that a spy!?!? No! It's Patroclus!
Clojure
30
star
6

paratest-selenium

An example of using ParaTest to speed up functional tests with Selenium2 and PHPUnit
PHP
23
star
7

indexed.db

The full IndexedDB API in ClojureScript
Clojure
22
star
8

mnemonic

BIP 39 implemented in Go
Go
11
star
9

nomnom

A simple library for converting byte sizes with PHP 5.3+
PHP
11
star
10

yoose

👷 A Clojure library for use case driven development
Clojure
10
star
11

php-classic-blog

A classic blog example built in PHP using domain driven and test driven principles
PHP
10
star
12

driven

A console app for creating testable domain driven PHP applications
PHP
8
star
13

old-site

personal site
JavaScript
7
star
14

dandy-roll

🎑 Watermarking via ClojureScript
Clojure
7
star
15

behavior-driven-todos

Demonstrating the full BDD lifecycle for GrPHPDev
PHP
4
star
16

awesome-covid-mask-making-companies

A list of companies helping combat COVID-19 through donations or direct aid.
4
star
17

nav-button

A simple NAV coin widget for displaying your nav address
JavaScript
3
star
18

nav-button-creator

Creates embeddable Nav Buttons
JavaScript
3
star
19

ansible-civicrm

Easily deploy CiviCRM to any number of remote hosts
PHP
2
star
20

how-do-i

How do I? Functional programming + speech recognition + how to videos in the browser
JavaScript
2
star
21

lemon-lime

Sprites for ClojureScript
Clojure
2
star
22

fsm

Yet another FSM library for Clojure(Script)
Clojure
2
star
23

entity

A simple starting point for Clojure(Script) entities
Clojure
2
star
24

dobby

Create ChatGPT agents in Clojure
Clojure
1
star
25

radmacs

My rad emacs setup
Emacs Lisp
1
star
26

go-env

A managed environment for a go api and client application using ansible and Vagrant
1
star
27

tea-mate

A simple tea timer app
JavaScript
1
star
28

chatty

a simple tcp/ip chat application written in node.js
JavaScript
1
star
29

policy-signer

Command line tool for dumping signed AWS S3 policies
JavaScript
1
star
30

blah

A library for working with microphones in ClojureScript
Clojure
1
star
31

drinkingtime

A simple app demonstrating typescript + krell + react-native + storybook
Java
1
star
32

pradpi

A Clojure library to simplify working with the Amazon Product Advertising API
Clojure
1
star
33

js-gladiators

Simple rpg style deathmatch in JS
JavaScript
1
star
34

vocloj

Clojure(Script) voice recognition and synthesis
Clojure
1
star
35

psssst

Keep your team abreast of open PRs that need review
Clojure
1
star