PHP
  Home arrow PHP arrow Page 4 - Dynamic Watermarking with PHP
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Dynamic Watermarking with PHP
By: Brian Vaughn
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 28
    2005-12-28


    Table of Contents:
  • Dynamic Watermarking with PHP
  • Cast and Crew
  • The Nuts and Bolts
  • Helper Functions
  • A Union of Images
  • Taking a Test Drive

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Dynamic Watermarking with PHP - Helper Functions
    ( Page 4 of 6 )

    Just to keep things simple, we’ve introduced two helper functions into our application. These functions are narrow in focus, each one performing a very specific task. By using them, however, we are able to clean up the code within our “create_watermark” function. Let’s add them to our class, then we’ll take a look at each:

    # average two colors given an alpha
    function _get_ave_color( $color_a, $color_b, $alpha_level ) {
          return round( ( ( $color_a * ( 1 - $alpha_level ) ) + ( $color_b  * $alpha_level ) ) );
    } # END _get_ave_color()
         
    # return closest pallette-color match for RGB values
    function _get_image_color($im, $r, $g, $b) {
          $c=imagecolorexact($im, $r, $g, $b);
          if ($c!=-1) return $c;
          $c=imagecolorallocate($im, $r, $g, $b);
          if ($c!=-1) return $c;
          return imagecolorclosest($im, $r, $g, $b);
    } # EBD _get_image_color()

    Our first function, “_get_ave_color”, accepts two color values, along with our (optional) user-specified alpha level, and returns a weighted average of the colors it has been passed. This function will help us blend the images we have been passed by averaging their colors at overlapping points.

    Next, “_get_image_color”, accepts an image object along with red, green, and blue color values. Using a few of the built-in PHP image-manipulation methods, this function then returns the closest available match (to the color specified) that exists within our image object’s color palette.

    In order to do this, it checks several things. First, if an exact match can be found, it is returned. If not, it will attempt to allocate a new palette color to match the one specified. If that fails as well, then as a last resort our function will simply return the closest pre-existing color match found within the images palette.

    If this seems a little confusing, don’t worry. It will make more sense once we put the pieces together.




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

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT