Home arrow PHP arrow Page 2 - Dynamic Watermarking with PHP

Cast and Crew - PHP

One of the things you can do with PHP's many functions for image handling and manipulation is create an image watermarking class. This will allow you to add a watermark to images, which can be useful for a number of purposes. Keep reading to learn how.

TABLE OF CONTENTS:
  1. Dynamic Watermarking with PHP
  2. Cast and Crew
  3. The Nuts and Bolts
  4. Helper Functions
  5. A Union of Images
  6. Taking a Test Drive
By: Brian Vaughn
Rating: starstarstarstarstar / 42
December 28, 2005

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Before we begin, let’s take a look at our cast and crew – that is, the functions we will be using to directly manipulate our images. A quick list of those functions is as follows:

# gives us the width & height values for a given image
imagesx()
imagesy()
 
# creates a new, true-color, image object
imagecreatetruecolor
 
# returns RGB (+ alpha) info for specific pixel of an image  
imagecolorsforindex()
 
# (similar as above), returns index of color for specific pixel
imagecolorat()
 
# sets a pixel to the specified color
imagesetpixel()
 
# given RGB values & an image object, the below functions will return a color index value ( that can then be passed to imagesetpixel() )
imagecolorexact()
imagecolorallocate()
imagecolorclosest()

As you can see, the above functions are each very narrow in their focus. Many of them are also probably self-explanatory. Don’t worry if any appear confusing though; their purposes will become clearer when we began placing them within our application.

The Story-Line

Now that we’ve defined the goals of our project, let’s take a step back and talk about the way we will be achieving these goals. At this point it’s okay to be very abstract; we’ll focus on the details shortly.

To begin, our application receives two image objects –- one the source image, and another the watermark image. The first thing we will need to do with these images is to determine their width and height. Once we have that information,  we can center-align our watermark. (For the purposes of our application, we are assuming that the watermark will always be smaller than the image we are attempting to protect/brand – probably a safe assumption in most cases.)

Next, our application should super-impose our watermark image on our source image. In order to do this, it will need to average the colors for any overlapping portions of those two images. This will give our resulting image the appearance of alpha transparency.

Finally, we’ll return our modified image for display in a browser. This way, our script can be called directly from within an “<img…>” tag.

Hopefully we’ve not discussed anything too complex so far. So now let’s take a look at the code.




 
 
>>> More PHP Articles          >>> More By Brian Vaughn
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: