WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : imageMarker v 3.00 with new advanced features
Categories : PHP, PHP Classes, Graphics, GD image library Click here to Update Your Picture
Hasin Hayder
Date : Jun 11th 2005
Grade : 3 of 5 (graded 7 times)
Viewed : 9432
File : 4179.zip
Images : No Images for this code example.
Search : More code by Hasin Hayder
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

image watermarker is an advanced advanced object oriented watermarker for php developers. it supports both way watermarking like text watermakring and image watermarking. beside these you have full control over watermarking process. version 2.00 supports only text watermarking and released under lesser gnu general public license. version 3.00 supports much more. this is version 3.00. you will get a fully commented source code of this class. usage file is included.

Features

» text watermarking
» text antialiasing
» text shadowing
» text rotaion
» watermark transparency
» any ttf font support
» any font size
» customizable horizontal and vertical spacing between two successive watermark
» using any image as watermark (v 3.00 only)
» transparency of image that used as watermark (v 3.00 only)
» transparent gif and png support (v 3.00 only)
» commented source code (v 3.00 only)


***** BEGIN imageMarker.php *****
<?
/********************************************************************************************************
* class name : watermarker
* developed by : hasin hayder
* version : 2.00
* date : 050509 10PM (9th may, 2005 , 10 PM)
* dependency : gd library and freetype
* homepage : http://hasin.phpxperts.com
*********************************************************************************************************
* version : 3.00
* date : 050512, 12:25 PM
* added : another image as water mark
* added : transparency of watermark image
* added : setting a specific color in watermark image fully transparent for specially transparen png or gif
* homepage : http://hasin.phpxperts.com
********************************************************************************************************/


class waterMarker
{
    var
$imagePath; //valid absolute path to image file
   
var $waterMarkText = "copyrighted"; //the text to draw as watermark
   
var $signature = "version 1.0"; //just the class file signature
   
var $font = "arial.ttf"; //font file to use for drawing text. need absolute path
   
var $size = 10; //font size
   
var $angle = 45; //angle to draw watermark text
   
var $hSpacing = 120; //horizontal spacing betweeen two sucessive watermark text
   
var $vSpacing = 120; //vertical spacing betweeen two sucessive watermark text
   
var $imageResource; //to store the image resource after completion of watermarking
   
var $imageType="jpg"; //image type of main image,  this could be either of png, jpg, jpeg, bmp, or gif (if gif then output will be in png)
   
var $wmimageType="jpg"; //image type or watermark image,  this could be either of png, jpg, jpeg, bmp, or gif
   
var $shadow = false; //if set to true then a shadow will be drawn under every watermark text
   
var $antialiased = true; //if set to true then watermark text will be drwan anti aliased. this is recommended
   
var $wmImagePath = ""; //the path of the image to watermark
   
var $drawMode = 0; //two mode is supported, 0 for text watermark, 1 for image watermark
   
var $transparency = 0;//transparency level
   
   
var $enableFullTransparency = false; //if this enabled, watermarkImages (fullTransparenColorAtX, fullTransparenColorAtY) pixels color will be fully transparent.
   
var $fullTransparentColorAtX = 0; //this (x) points color will be made full transparent
   
var $fullTransparentColorAtY = 0; //this (y) points color will be made full transparent

   
function __processImage($__imageType, $__mode)
   
/*********************************************************************************************
    * private function for returning generalized image create and deploy proc's, dont use directly
    * params : $__mode is the mode of operation
    * $__mode should be 0 for image create proc
    * $__mode should be 1 for image deploy proc
    * $__imageType is the image type for these procs, could be jpg, jpeg, bmp, png or gif
    * return value : variable function for creating and deplying images
    **********************************************************************************************/
   
{
            switch (
$__imageType)
        {
       
/************************************************************************
        * this portion uses PHP's advanced variable function facility
        * and determine generalized function to create and deply images.
        * $createProc is a generalized reference of image creation function
        * $outputProc is a generalized reference of image deploying functionm
        ************************************************************************/
               
case "png":
               
$createProc = "imagecreatefrompng";
               
$outputProc = "imagepng";
                break;
                case
"gif";
               
$createProc = "imagecreatefromgif";
                       
$outputProc = "imagepng";
                        break;
                case
"bmp";
               
$createProc = "imagecreatefrombmp";
                       
$outputProc = "imagebmp";
                        break;
                case
"jpeg":
            case
"jpg":
               
$createProc = "imagecreatefromjpeg";
                       
$outputProc = "imagejpeg";
                        break;

        }
       
        switch (
$__mode)
       
//now handle the mode of operation
       
{
                case
0:
                return
$createProc;
                break;
                case
1:
                return
$outputProc;
                break;
        }
   
    }
   
    function
mark()
    {
   
/****************************************************************
    * this function draw the watermark over the image
    * parameteres : none
    * return value : image resource after completion of watermarking
    ****************************************************************/
   
   
       
list($width, $height, $type, $attr) = getimagesize($this->imagePath); //get basic properties of the image file

    /************************************************************************
    * initialize main create and deploy procedures
    ************************************************************************/
   
$__mainImageCreateProc =$this->__processImage($this->imageType, 0);
   
$__mainImageDeployProc =$this->__processImage($this->imageType, 1);

   
/**************************************************************************
    * initialize watermark imnage create and deploy procedures if drawMode = 1
    **************************************************************************/
   
if ($this->drawMode==1)
    {
       
$__wmImageCreateProc =$this->__processImage($this->wmimageType, 0);
       
$__wmImageDeployProc =$this->__processImage($this->wmimageType, 1);
       
$wm = $__wmImageCreateProc($this->wmimagePath); //open the watermark image with generalized create function
       
list($wmwidth, $wmheight, $wmtype, $wmattr) = getimagesize($this->wmimagePath); //get basic properties of the image file
   
}
       
$im = $__mainImageCreateProc($this->imagePath); //open the image with generalized create function

       
$grey = imagecolorallocate($im, 180, 180, 180); //color for watermark text
       
$shadowColor = imagecolorallocate($im, 130, 130, 130); //color for shadow text

       
if (!$this->antialiased)
       
/******************************************************************************
        * if its need to draw non-antialiased text then just set the color = -1*color
        * then the text drawn with this color will be sharp (non-antialiased)
        ******************************************************************************/
       
{
           
$grey *= -1; //grey = grey * -1
           
$shadowColor *= -1; //shadowColor = shadowColor * -1
       
}
       
       

        if(
$this->drawMode==0)
        {
       
//start drawing watermark text
           
for ($x=20; $x<$width; $x+=$this->hSpacing)
               
/*******************************************
                * now draw water mark text and shadow text
                *******************************************/
               
{
                        for (
$y=20; $y<$height; $y+=$this->vSpacing)
                        {


                    if (
$this->shadow) imagettftext($im, $this->size, $this->angle, $x+1, $y+1, $shadowColor, $this->font, $this->waterMarkText); //draw shadow text over image
                               
imagettftext($im, $this->size, $this->angle, $x, $y, $grey, $this->font, $this->waterMarkText); //draw text over image
                       
}
                }
               
$this->imageResource= $__mainImageDeployProc($im); //deploy the image with generalized deploy function
           
}

        if(
$this->drawMode==1)
        {


       
/******************************************************************************************************
        * this portion sets color of pixel (fullTransparenColorAtX,fullTransparenColorAtY) as transparent color
        ******************************************************************************************************/
       
if($this->enableFullTransparency==true)
        {
           
$tpcolor = imagecolorat($wm, $this->fullTransparentColorAtX, $this->fullTransparentColorAtY);
           
imagecolortransparent($wm, $tpcolor);
        }
         
/*****************************************************************************************************/
       
       
        //start drawing watermark image
           
for ($x=20; $x<$width; $x+=$this->hSpacing)
               
/*******************************************
                * now draw water mark image
                *******************************************/
               
{
                        for (
$y=20; $y<$width; $y+=$this->vSpacing)
                        {
                   
imagecopymerge($im, $wm, $x, $y,0,0,$wmwidth, $wmheight,$this->transparency); //draw waterMark image over main image
                       
}
                }
               
$this->imageResource= $__mainImageDeployProc($im); //deploy the image with generalized deploy function
           
}

       
imagedestroy($im);
       
imagedestroy($wm);
    }
}
?>




sample code
<?
/*******************************************
* usage of this waterMark class
*******************************************/
include_once("imageMarker.php");
$imagePath = $_REQUEST['code']; //image to watermark
$imark = new waterMarker(); //initiate
$imark->angle=45; //angle for text marking
$imark->waterMarkText = "phpexperts";
$imark->wmimagePath = "angel.png"; //image to use as watermark
$imark->enableFullTransparency=true; //enable GIF/PNG transparency
$imark->transparency=20; //alpha percentage
$imark->shadow = true; //create shadow
$imark->wmimageType = "png";
$imark->drawMode = 1; //turn on image watermarking
$imark->imagePath = $imagePath;
$imark->font="arial.ttf"; //font file that must be in this dir
$imark->size = 14;
$imark->hSpacing=110; //horizontal spacing
$imark->vSpacing=110; //vertical spacing
header("Content-type: image/jpeg");
$imark->mark(); //draw watermark
?>


thanks
hasin hayder
http://hasin.phpxperts.com



Advanced Image WaterMarker
Categories : PHP, PHP Classes, GD image library, Graphics, Object Oriented
Image Generation Class ( PNG Format )
Categories : PHP, GD image library, PHP Classes, Graphics
EasyPhpThumbnail Class - The EasyPhpThumbnail class allows you to generate thumbnails and handle image manipulation for GIF, JPG and PNG on-the-fly.
Categories : PHP, PHP Classes, Object Oriented, Graphics, GD image library
Simple class that uses GD to draw pie charts. After the class definition there's some sample code to demonstrate how you use the class.
Categories : Graphics, PHP, PHP Classes, GD image library, Charts and Graphs
crop and resize image class using gd library function
Categories : PHP, PHP Classes, GD image library, Graphics
PHP Email image generator - hide your email from bots - using the GD Library
Categories : PHP, Graphics, GD image library, Beginner Guides
Three Cool Classes and One Trick
Categories : PHP, PHP Classes, Graphics, Email
PHP Image Class
Categories : PHP, PHP Classes, Multimedia, GD image library
A class to draw real 3D graphics with surface area
Categories : Graphics, PHP, PHP Classes
A damaged image generator (class) for validating text. CAPTCHA - Completely Automated Public Turing test to tell Computers and Humans Apart
Categories : PHP, PHP Classes, Security, GD image library, Security
Display a bar chart based on random values.
Categories : Graphics, PHP, GD image library, Charts and Graphs
PHP interface class to the eBusiness Charts generatation remote service.
Categories : PHP, PHP Classes, Graphics, Charts and Graphs
HTML_Graphs uses PHP to provide a consistent interface for creating HTML based charts. The user of the class sets up arrays that are passed to html_graph() which then takes care of all the messy HTML layout.
Categories : Graphics, Arrays, PHP, PHP Classes, Charts and Graphs
Simple PHP Bar Graph using GD library
Categories : PHP, GD image library, Graphics, Arrays
A captcha image allows you to prevent spam posting when users reload the page and stop bots from submitting forms automatically. This version allows you to use your own fonts (.ttf) to show the text.
Categories : PHP, Security, Graphics, GD image library