WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
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 Index
Web Development Resources
Web Development Content
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
Mobile Dev World

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 : Advanced Image WaterMarker
Categories : PHP, PHP Classes, GD image library, Graphics, Object Oriented Click here to Update Your Picture
Hasin Hayder
Date : May 10th 2005
Grade : 4 of 5 (graded 11 times)
Viewed : 11156
File : 4165.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 
 

This is an advanced waterMarker class for PHP. With this, you can watermark your images with many features. It supports the followings

1. Angle of Text
2. Shadowed Text
3. Smooth Text(Antialiasing), Sharp Text(Non-Antialiasing)
4. Any Image Format, you have no extra overload
5. Any FontSize
6. Any TTF Font
7. Customizable Horizontal and Vertical Spacing between two successive watermark
8. Supports Direct Watermarking over http protocol and also relative or absolute path of image file. I mean if u use this type code http://urdomain.com/imageMarker.php?code=http://anotherdomain/image.jpg it will also work.

This image watermarker is fully commented. Its will really be helpful for many of you.

Thanks
Hasin Hayder
http://hasin.phpxperts.com

ImageMarker.php
<?
/*****************************************
* class name : watermarker
* developed by : hasin hayder
* date : 050509 10PM (9th may, 2005 , 10 PM)
* dependency : gd library and freetype
* version : 2.00
*****************************************/

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"; //this could be either of png, jpg, jpeg, bmp, or gif (if gif then output will be in png)
   
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
   
   
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

       
switch ($this->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;
                       
        }
       
       
$im = $createProc($this->imagePath); //create the image with generalized image 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
       
}
       
       
           
            for (
$x=20; $x<$width; $x+=$this->hSpacing)
           
/*******************************************
            * now draw water mark text and shadow text
            *******************************************/
           
{
                    for (
$y=20; $y<$width; $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= $outputProc($im); //deploy the image with generalized image deploy function
           
   
}
}
?>


Ussage
<?php
include_once("imageMarker.php");
/*******************************************
* usage of this waterMark class
*******************************************/
$imagePath = $_REQUEST['code'];
//echo $imagePath;
$imark = new waterMarker();
$imark->waterMarkText = "bdtemplates";
$imark->imagePath = $imagePath;
$imark->font="arial.ttf";
$imark->size = 14;
$imark->hSpacing=110;
$imark->vSpacing=110;
$imark->shadow=true;
$imark->angle = 45;
header("Content-type: image/jpeg");
$imark->mark(); //draw watermark
//echo $imark->imageResource;
echo $imark->imageResource;
?>



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
Image Generation Class ( PNG Format )
Categories : PHP, GD image library, PHP Classes, Graphics
imageMarker v 3.00 with new advanced features
Categories : PHP, PHP Classes, Graphics, GD image library
Generate image with random number (CAPTCHA)
Categories : PHP, GD image library, Graphics, Security
Render TTF Text to PNG. Text message, font, size, rotation, padding, color, background, and transparency can all be defined via URL.
Categories : PHP, PHP Classes, Graphics
HTML_Graphs provides a simple PHP interface for creating pure HTML charts.
Categories : Graphics, PHP, PHP Classes, Charts and Graphs
Image Cache
Categories : Graphics, PHP Classes, PHP
PHPDRAW, the php wannabe Photoshop ;-)
Categories : PHP, PHP Classes, GD image library, Arrays
Create Thumbnails - resize an image - jpeg, jpg, gif, png to the specifed width and height in proportion without loosing out on pixcel quality.
Categories : PHP, GD image library, Graphics
Create a Thumbnail Using PHP, GD and Exif
Categories : PHP, Graphics, Exif, GD image library
A class to draw real 3D graphics with surface area
Categories : Graphics, PHP, PHP Classes
Three Cool Classes and One Trick
Categories : PHP, PHP Classes, Graphics, Email
PHP Email image generator - hide your email from bots - using the GD Library
Categories : PHP, Graphics, GD image library, Beginner Guides