359 Lotus blogs updated hourly. Who will post next? Home | Downloads | Events | Pods | Blogs | Search | myPL | About 
 
Latest 7 Posts
Integrating the Bluemix Watson Translation service into an XPages application
Sun, Oct 19th 2014 289
Oh duh, that is why Node Package Manager (npm) is so cool
Tue, Oct 14th 2014 312
Create your own Watson Q and A example with Bluemix, Webstorm and Jazz Hub
Sun, Oct 12th 2014 728
Getting into IBM Bluemix….this could be interesting
Wed, Oct 8th 2014 241
Opening an XPage in XPiNC and passing Query_String parameters
Tue, Sep 30th 2014 180
Closing soon: IBM Domino/Notes Community Survey
Mon, Sep 29th 2014 256
What is a social presence worth?
Sun, Sep 21st 2014 221
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 1211
Create your own Watson Q and A example with Bluemix, Webstorm and Jazz Hub
Sun, Oct 12th 2014 728
Running an XPages/Angular.js application on a Bluemix site
Wed, Sep 17th 2014 539
Going to MWLUG 2014? Buy Dave Leedy a beer
Sun, Aug 24th 2014 435
Angular.js in XPages #7 – Writing better code using Services
Sun, Aug 3rd 2014 419
Speaking at MWLUG 2014: Write once, run anywhere – Angular.js in XPages
Tue, Jul 8th 2014 387
EXTJS in XPages #13: Totaling your columns with a groupingSummary
Sun, Jun 30th 2013 378
Taking back productivity in Domino Designer (a NotesIn9 production)
Tue, Jul 29th 2014 374
Hi Chicago – what changed?
Wed, Jul 2nd 2014 363
Web Components – Entering the ShadowDOM….
Wed, Jul 9th 2014 334


jQuery in XPages #6 – watermark.js
MarkyRoden    

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!

Introduction

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.

Demonstration

The effect is demonstrated here

Download

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.

watermark.js

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;
document.body.appendChild(canvas);
// 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">
		<xp:this.value><![CDATA[
		$(document).watermark({
			path: '#{compositeData.path}',
			className: '#{compositeData.className}',
			opacity: '#{compositeData.opacity}',
			position: '#{compositeData.position}',
			watermark: '#{compositeData.watermark}'
		});
		]]></xp:this.value>
	</xp:scriptBlock>

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:tr>
			<xp:td style="width:50%">
				<xp:image url="/Nin9TV.jpg" id="image1" styleClass="watermark">
				</xp:image>
			</xp:td>
			<xp:td>
				<xp:image url="/xpages.jpg" id="image2" styleClass="watermark">
				</xp:image>
			</xp:td>
		</xp:tr>
	</xp:table>

Demonstration

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




---------------------
http://xomino.com/2012/04/17/jquery-in-xpages-6-watermark-js/
Apr 17, 2012
48 hits



Recent Blog Posts
289


Integrating the Bluemix Watson Translation service into an XPages application
Sun, Oct 19th 2014 7:07p   Mark Roden
In this article I will demonstrate how to integrate the Bluemix Watson Translation service into a functioning XPages application. Bluemix Watson Translation Service Following on from one from my previous posts on the subject I have been looking for a good workable example of using a Bluemix service within an XPages application. As I said before this is as much an exercise in me learning more about node.js and Bluemix as anything else – but I also love being able to share. Based on the [read] Keywords: domino ibm notes xpages ajax application development server xml
312


Oh duh, that is why Node Package Manager (npm) is so cool
Tue, Oct 14th 2014 9:07p   Mark Roden
I am in the process of playing with Bluemix and part of the reason or this is to learn more about node.js. It is really cool to learn something new and also to broaden the mind. But I digress – Node Package Manager (npm) makes using node.js so simple it is mind boggling… Without going into masses of detail on node.js (which I might at some point) here is the simple example of what I am trying to do and why npm is so cool. Node Package Manager (npm) allows you to install any node [read] Keywords: application applications interface
728


Create your own Watson Q and A example with Bluemix, Webstorm and Jazz Hub
Sun, Oct 12th 2014 10:19p   Mark Roden
Introduction In this article I will demonstrate how to get up and running with one of the Bluemix/Watson service examples. I will be using the example provided by IBM in their documentation as the basis for the article but the way in which I achieved the final goal was quite different from the way that they explained it in the example. This example will use: IBM Bluemix as my service provider The Watson Question and Answer service A Node.js service to host the website JetBrains Webstorm IDE [read] Keywords: domino ibm application css integration javascript password server
241


Getting into IBM Bluemix….this could be interesting
Wed, Oct 8th 2014 7:12p   Mark Roden
My interest in IBM Bluemix has grown since it was announced. I took part in the Beta, but frankly didn’t do very much because I really couldn’t figure out what it was or why I cared. Since then though IBM has announced that they are investigating putting Domino into Bluemix. Before I start down this path I have to say at this point that I have no idea what “Domino in Bluemix” even means. I have no idea what that will look like and while I would love to second guess a [read] Keywords: domino ibm xpages application applications development interface java mobile server
180


Opening an XPage in XPiNC and passing Query_String parameters
Tue, Sep 30th 2014 7:22p   Mark Roden
I was very pleasantly surprised to find this works – coincidentally – twice this week someone has asked this question – can I open an XPage in XPiNC directly? I thought the answer was no……and not for the first (and/or last) time I was wrong. The answer lies here – http://www-10.lotus.com/ldd/ddwiki.nsf/dx/Domino_Designer_URLs_for_XPages To prove it I created a plain XPage and added the firebugLite custom control The following XPiNC URL notes://copper/882579C [read] Keywords: ldd lotus notes
256


Closing soon: IBM Domino/Notes Community Survey
Mon, Sep 29th 2014 11:12a   Mark Roden
For the last two weeks PSC has been asking for input from the ICS community on what companies are planning on doing with their Domino Infrastructure. If you have not already done so, please take a couple of minutes to help. The results will be posted next week. http://bit.ly/PSCXPagesSurvey [read] Keywords: domino dominonotes ibm notes community




221


What is a social presence worth?
Sun, Sep 21st 2014 7:51p   Mark Roden
We had an interesting discussion internally at work about what exactly does our “Social Presence” do for us? I put time and thought to it and it turns out to be a question I can answer on many levels. I am still not entirely sure what the answer is. What does being social mean? Being social means sharing through ideas, code, concepts, dreams….anything really – but sharing it. Within the XPages community we have a multitude of people who are social for many different r [read] Keywords: domino ibm xpages community development java office sharepoint
539


Running an XPages/Angular.js application on a Bluemix site
Wed, Sep 17th 2014 7:48p   Mark Roden
In this article I will show you how to run an XPages application based on Angular data within a Bluemix based website. Introduction For background reading on this article please review my series on Angular.js in XPages starting here. I will be using the application described within that article as the starting point for this article. A little background on Bluemix Bluemix is IBM’s new Platform as a Service (PaaS) system which provides the end to end cloud based hosting of application [read] Keywords: domino ibm xpages application applications bug community database interface server skype
221


MWLUG 2014 Slide Deck – Write once, run anywhere: Angular.js in XPages.
Tue, Sep 2nd 2014 1:05p   Mark Roden
Here is the slide deck for those interested – thank you to everyone who attended the presentation and I look forward to talking more on the subject in the future. http://www.slideshare.net/MarkRoden/angularjs-in-xpages [read] Keywords: xpages
263


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:




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