Ben Nadel

Subscribe to Ben Nadel: eMailAlertsEmail Alerts
Get Ben Nadel: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Related Topics: ColdFusion on Ulitzer

CFDJ: Article

CFImage Part 3

Watermarks and transparency

ColdFusion 8 introduces the CFImage tag and dozens of image manipulation functions. We have already looked at reading and writing image files and we have covered the basic yet powerful image manipulation possible through CFImage tag actions alone. Now we know enough to be able to really start exploring the vast feature set of ColdFusion 8 image manipulation. When it comes to something like this your imagination is really the only limit, so it makes it a bit more difficult to come up with simple ways to learn this stuff. I find that task-based learning works well and will let us accomplish real-world goals while touching on many aspects of image manipulation.

We'll also cover adding watermarks to photos. There are a number of ways to do this like building the watermark from scratch or using an existing watermark image. To start with, I'm going to demonstrate using an existing watermark image. Hands down, this is going to give you the best results. ColdFusion 8 provides amazing image manipulation, but it's not a replacement for an image/photo editing application such as Adobe Fireworks (nor was that ever the intention).

To create my watermark image, I'm going to open up my sweet-ass Fireworks application and create a transparent canvas. The transparent canvas is important because we don't want the overlaid image to be too obvious. Then I'm going to type "Kinky Solutions" and give it a nice orange glow affect:

Notice that the background of this canvas (in Adobe Fireworks) has a checkered white-and-gray pattern. This signifies that the background is transparent. Then I export this image as a PNG32. This will compress the image while maintaining transparency.

Now, let's take a look at the image we're working with and the watermark we're going to apply:

<!--- Read in the original image. --->
<cfset objImage = ImageRead( "./blue_eyes.jpg" ) />

<!--- Write it to the browser. --->
<cfimage
     action="writetobrowser"
     source="#objImage#"
     />

<!--- Read in the Kinky Solutions watermark. --->
<cfset objWatermark = ImageNew(
     "./kinky_solutions_watermark_png32.png"
     ) />

<!--- Write it to the browser. --->
<cfimage
     action="writetobrowser"
     source="#objWatermark#"
     />

Running this code, we get the following output:


More Stories By Ben Nadel

Ben Nadel has worked with ColdFusion for eight years and is a super ColdFusion enthusiast. He blogs regularly about all aspects of Web development on his personal site, http://www.bennadel.com, and does his best to give back to the ColdFusion community through online code demos and his "Ask Ben" blog posts. He is also a Certified Advanced ColdFusion MX7 developer and is one of the lead programmers at Nylon Technology.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.