357 Lotus blogs updated hourly. Who will post next? Home | Downloads | Events | Pods | Blogs | Search | myPL | About 
Latest 7 Posts
Going to MWLUG 2014? You need to buy these guys a beer as well….
Sun, Aug 24th 2014 179
Going to MWLUG 2014? Buy Dave Leedy a beer
Sun, Aug 24th 2014 344
Chart Directives and Dynamic Binding – MWLUG 2014 preview
Wed, Aug 20th 2014 202
Accessing the original element when using Select2-focus
Sun, Aug 17th 2014 152
Angular in XPages #8 – Directives (did someone say plugins?)
Sun, Aug 10th 2014 178
Working on my MWLUG2014 presentation
Wed, Aug 6th 2014 208
Angular.js in XPages #7 – Writing better code using Services
Sun, Aug 3rd 2014 326
Top 10
Arguably the most dangerous thing you could ever do in XPages – let other people use your eval() in their SSJS
Tue, Jun 18th 2013 1248
Why learning JavaScript is more critical to XPage developers than Java
Wed, Mar 26th 2014 999
An open letter to Mr. NotesIn9
Wed, Apr 2nd 2014 660
Adding custom HTTP headers to Domino R9 using IBM HTTP Server (IHS)
Sun, Apr 20th 2014 628
Angular.js in XPages #1 – Using the right IDE for development
Sun, Apr 27th 2014 560
WebSockets comes to XPages!! Awesome – Awesome – Awesome
Tue, May 20th 2014 554
EXTJS in XPages #13: Totaling your columns with a groupingSummary
Sun, Jun 30th 2013 544
EXTJS in XPages #14 – Grid editing and saving data via REST CRUD
Thu, Aug 1st 2013 542
And the gloves are off……
Mon, Mar 31st 2014 540
Angular.js in XPages #6 – A People Manager CRUD application
Sun, Jun 1st 2014 484

jQuery in XPages #6 – watermark.js

In this article I will demonstrate how to implement watermark.js by Patrick Wied. Using the power of HTML5 image manipulation we are able to add a watermark graphic to another image and determine position and opacity - even with a JPG!! Of course that means no IE but hey we’re looking forward not backward people!


This week I am only going to use one article because this hopefully won’t be too long. I am also going to try and break the article down into a simpler format than before, highlighting the XPages techniques as well as the jQuery techniques. Thanks to David Leedy for the feedback on article format and content.


The effect is demonstrated here


The demonstration database can be downloaded from the link above or from here

Opacity in images

JPEG has been the standard web format for many years and was fantastic when we were able to reduce the size of images to (good enough) over a slow connection. Nowadays though the need to have image capability is opacity. PNG files are now the go to image format for the web and like GIF they support an A(lpha) channel which allows for an opacity to be applied to the image directly.


Looping through all pixels in an image – using JavaScript!

watermark.js uses a new feature in HTML5 whereby each pixel of a graphic can be manipulated from JavaScript, including the addition of an alpha (opactiy) value. The original article by Patrick explains how some very simple loop code can be written to go through each pixel in an image and apply an opacity.

First we have to create a canvas element, add it to the document’s body, set the canvas size to the image size (we have a 500×200 img) and add the image to the canvas.

// get the image
var img = document.getElementById("your-image");
// create and customize the canvas
var canvas = document.createElement("canvas");
canvas.width = 500;
canvas.height = 200;
// get the context
var ctx = canvas.getContext("2d");
// draw the image into the canvas
ctx.drawImage(img, 0, 0);

“Ok this is the more interesting part of the solution. We have to access the image data, loop thru all pixels of the image and set the alpha values to the value of our choice. A pixel in the imagedata is represented by four values: red, green, blue, alpha (rgba) therefore we have to change every fourth value.”

// get the image data object
var image = ctx.getImageData(0, 0, 500, 200);
// get the image data values
var imageData = image.data,
length = imageData.length;
// set every fourth value to 50
for(var i=3; i < length; i+=4){
    imageData[i] = 50;
// after the manipulation, reset the data
image.data = imageData;
// and put the imagedata back to the canvas
ctx.putImageData(image, 0, 0);

And here’s what we are going to build – an image with another opaque image surfaced on top of is as a watermark.

Our watermarked image

Our watermarked image

The watermark custom control

We are going to build an XPages watermark custom control whereby the developer can determine all the parameters of the effect through the custom properties of the control and therefore not have to change any of the underlying code.

There are 5 parameters which go with the jQuery plugin for watermark.js

  1. “className”: the class of the elements which should get a mark. (Optionally) Default: “watermark”
  2. “position”: “top-left”|”top-right”|”bottom-right”|”bottom-left”. (Optionally) Default: “bottom-right”
  3. “watermark”: an img element which represents your watermark. (Optionally)
  4. “path”: the path to your watermark image. (Optionally)
  5. “opacity”: opacity percentage, no “%” only the number [0-100] (Optionally) Default: 50

So we create the custom control in our database and under the “Property Definition” section we add our “properties”. Each property is a string except the position which is a combobox with pre-defined parameters.

Property Definition of a Custom Control

formWatermark Property Definitions

formWatermark Property Definitions

Entering custom properties to your custom control

And when we add the custom control to our XPage we are able to fill in the parameters for the control

Adding parameter values to our custom control in the XPage

Adding parameter values to our custom control in the XPage

Accessing the custom properties through the XPage

Accessing the custom properties through the XPage is achieved using compositeData.whateverParameterName. As you can see from the above example though not all the fields need to be filled in – so we need to compute their inclusion on the plugin instantiation.

This is the code used to create the effect. It must be added through and output script in the XPage because we need access to the Server Side variable computation which is not available through a Client Side library.

<xp:scriptBlock id="scriptBlock1">
			path: '#{compositeData.path}',
			className: '#{compositeData.className}',
			opacity: '#{compositeData.opacity}',
			position: '#{compositeData.position}',
			watermark: '#{compositeData.watermark}'

Watermark these images
Unless otherwise stated in the parameters the watermark.js effect is applied to all images with the class=”watermark”. Here are my images from the database.

	<xp:table style="width:100%" id="table1">
			<xp:td style="width:50%">
				<xp:image url="/Nin9TV.jpg" id="image1" styleClass="watermark">
				<xp:image url="/xpages.jpg" id="image2" styleClass="watermark">


The demonstration site shows a number of possibilities and allows the developer to change the variables and see the effect.

Demonstration of using watermark.js in an XPage

Demonstration of using watermark.js in an XPage

Apr 17, 2012
69 hits

Recent Blog Posts

Going to MWLUG 2014? You need to buy these guys a beer as well….
Sun, Aug 24th 2014 8:07p   Mark Roden
—->>>> Richard Moy [read] Keywords:

Going to MWLUG 2014? Buy Dave Leedy a beer
Sun, Aug 24th 2014 5:37p   Mark Roden
Yeah I know I have rattled on about this before but it holds as true today as it does any other day before. Here is a list of reasons you should buy Dave Leedy a beer in case you were wondering… 1) really? You need a list?? Shame on you…. 2) NotesIn9 has helped you – One of those videos by Dave, John, John, Brian, Chris, Graham, Jeremy, Mark, Mark, Paul, Peter, Steve, Tim, Chris, Paul, Josh, Dan, Niklas, Michael, Russ, Serdar, Sean, Mark, Brad, Frederick, Steve, Richard, Kathy, [read] Keywords: ibm community

Chart Directives and Dynamic Binding – MWLUG 2014 preview
Wed, Aug 20th 2014 7:13p   Mark Roden
Although not directly related to the purpose of the presentation I am going to demonstrate how to use an Angular.js chart directive to bind to the application service data and create dynamic charting within the application. Changing the Zip for 1 Marky not only updates the data displayed – but also because of the data bind – auto-magically updates the chart While this in itself does not directly relate to the write once and run anywhere nature of the presentation – it d [read] Keywords: application

Accessing the original element when using Select2-focus
Sun, Aug 17th 2014 7:36p   Mark Roden
In the application we are currently working on I wanted to add an ajax call to a JSON service, but only for certain fields. Rather than go through the application and add the code to every element I used a delegated focus event for the field with an attribute of  “help_fieldName”. The following HTML represents the code on the form: UK US Global First Name Last Name The following jQuery code makes it work. The getHelp function shows/hides [read] Keywords: ajax application xml

Angular in XPages #8 – Directives (did someone say plugins?)
Sun, Aug 10th 2014 8:08p   Mark Roden
In this article I will discuss Angular Directives and why they are near and dear to my heart Directives Directives in Angular are modular pieces of functionality which in some cases are very analogous to plugins in jQuery. According to the Angular documentation… “At a high level, directives are markers on a DOM element (such as an attribute, element name, comment or CSS class) that tell AngularJS’s HTML compiler ($compile) to attach a specified behavior to that DOM element or [read] Keywords: xpages application css

Working on my MWLUG2014 presentation
Wed, Aug 6th 2014 8:04p   Mark Roden
Just wanted to show a work in progress – screenshots of what I am working on for MWLUG2014. Part of the presentation is showing how to make your Angular applications portable. My sample app will be the one I created as part of the Angular in XPages series. I will walk through the code and demonstrate how I can take this stand alone application and insert it into this bootstrap demo dashboard application creating this fully functional component capability within the dashboard With [read] Keywords: xpages application applications

Angular.js in XPages #7 – Writing better code using Services
Sun, Aug 3rd 2014 6:01p   Mark Roden
In this article I will discuss a better programming practice for Angular.js than was demonstrated in the previous articles within this series. I have mentioned before, part of the purpose this blog is very much a “learning in progress” for me. Without going through the previous articles I would not have been able to get to this point and write “better code”. Hopefully with that understanding, those of you who have been along for the ride will appreciate this and grow w [read] Keywords: agent lotusscript xpages application twitter


Taking back productivity in Domino Designer (a NotesIn9 production)
Tue, Jul 29th 2014 3:27p   Mark Roden
Yeah it has been a while (over 18 months) since the last time I did a NotesIn9 video but it finally happened again. NotesIn9 149:  Database Resources and Design Definition Doesn’t sound very exciting does it? Dave needs to work on his attention grabbing heading show names. I would have called it something more like this – but then who am I to complain – it is not my show after all ;) NotesIn9 149:  Taking back productivity in Domino Designer  This video revolves around som [read] Keywords: domino notes xpages database eclipse

The consummate Champion
Thu, Jul 24th 2014 8:42p   Mark Roden
As Russ Maher said today in Hey Who got the Handsome Champion it is an honor and a privilege to not only be recognized by IBM as a Champion for ICS 2014, but you also get some very cool stuff. Thanks to Amanda Bauman and Oliver Heinz for organizing “the champions” and all the gear. I just wonder what I am going to do with all of it :) Seriously though, I am very humbled to be an IBM Champion ! Thank you to everyone who nominated me and made this possible :) [read] Keywords: ibm

Web Components – Entering the ShadowDOM….
Wed, Jul 9th 2014 9:18p   Mark Roden
Web Components – the future You should first ground yourself on Web Components and read this article on Web Components and concepts, ShadowDOM, imports, templates, custom elements by Todd Motto. Then listen to this Podcast (thanks to Steve for pointing it out) - Web Components with Peter Gasston Once you have read/listened you will have some idea and concept about Web Components and how they are the future….. But what I wanted to show briefly was how to enable the ShadowDOM in C [read] Keywords: agent javascript podcast

Created and Maintained by Yancy Lent - About - Blog Submission - Suggestions - Change Log - Blog Widget - Advertising - Mobile Edition