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
PHP Web Logs (BLogs)
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
Submit Site
Forex Trading Online forex trading platform

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 : Place a watermark for every image you upload.
Categories : PHP, Graphics, GD image library
Moiz Sitabkhan
Date : May 20th 2007
Grade : 5 of 5 (graded 1 times)
Viewed : 2155
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Moiz Sitabkhan
Action : Grade This Code Example
Tools : My Examples List

 
Like this code?
Show the author your appreciation.
Submit your own code examples 
 

This function is really cool. Helps you to place a watermark image on your pics so that others cannot download copyright images. Now this function accepts 3 parameters ( self descriptive)...<br>
1. $sourcefile - the file with you want to place a watermark on.
2. $watermarkfile - a file which is a 24 bit PNG file which has the image you want to embed.
3. $saveFile - location of the new file with the watermark along with the filename.

Remember to call this function after you have successfully uploaded a file.
Provide the exact path of the file you uploaded.

<?php
function watermark($sourcefile, $watermarkfile, $saveFile)
{
   
#
    # $sourcefile = Filename of the picture to be watermarked.
    # $watermarkfile = Filename of the 24-bit PNG watermark file.
    #
   
    //Get the resource ids of the pictures
   
$watermarkfile_id = imagecreatefrompng($watermarkfile);
   
   
imageAlphaBlending($watermarkfile_id, false);
   
imageSaveAlpha($watermarkfile_id, true);
   
$fileType = strtolower(substr($sourcefile, strlen($sourcefile)-3));
   
    switch(
$fileType)
    {
        case(
'gif'):
           
$sourcefile_id = imagecreatefromgif($sourcefile);
        break;
       
        case(
'png'):
           
$sourcefile_id = imagecreatefrompng($sourcefile);
        break;
       
        default:
           
$sourcefile_id = imagecreatefromjpeg($sourcefile);
    }
   
   
//Get the sizes of both pix   
   
$sourcefile_width=imageSX($sourcefile_id);
   
$sourcefile_height=imageSY($sourcefile_id);
   
$watermarkfile_width=imageSX($watermarkfile_id);
   
$watermarkfile_height=imageSY($watermarkfile_id);
   
    if(isset(
$_REQUEST['imgPhoto_x']))
    {       
       
$dest_x = $_REQUEST['imgPhoto_x'];
       
$dest_y = $_REQUEST['imgPhoto_y'];
    }
    else
    {
       
$dest_x = ( $sourcefile_width / 2 ) - ( $watermarkfile_width / 2 );
       
$dest_y = ( $sourcefile_height / 2 ) - ( $watermarkfile_height / 2 );
    }   
   
   
// if a gif, we have to upsample it to a truecolor image
   
if($fileType == 'gif')
    {
       
// create an empty truecolor container
       
$tempimage = imagecreatetruecolor($sourcefile_width,$sourcefile_height);
       
       
// copy the 8-bit gif into the truecolor image
       
imagecopy($tempimage, $sourcefile_id, 0, 0, 0, 0,$sourcefile_width, $sourcefile_height);
       
       
// copy the source_id int
       
$sourcefile_id = $tempimage;
    }
   
imagecopy($sourcefile_id, $watermarkfile_id, $dest_x, $dest_y, 0, 0,$watermarkfile_width, $watermarkfile_height);
   
//Create a jpeg out of the modified picture
   
switch($fileType)
    {
       
// remember we don't need gif any more, so we use only png or jpeg.
        // See the upsaple code immediately above to see how we handle gifs
       
case('png'):
           
//header("Content-type: image/png");
           
imagepng ($sourcefile_id);
        break;
       
        default:
           
//header("Content-type: image/jpg");
           
if(imagejpeg ($sourcefile_id,$saveFile))
            {
            }
       
//echo "<img src='$saveFile'>";
   
}       
     
   
imagedestroy($sourcefile_id);
   
imagedestroy($watermarkfile_id);
    return
true;
}
?>



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
PHP Image Compression using GD library
Categories : PHP, Compression, GD image library, Graphics
Line graphics generation library written in PHP + GD library (spanish comments)
Categories : PHP, Graphics, GD image library
imageMarker v 3.00 with new advanced features
Categories : PHP, PHP Classes, Graphics, GD image library
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
Image Generation Class ( PNG Format )
Categories : PHP, GD image library, PHP Classes, Graphics
Generate image with random number (CAPTCHA)
Categories : PHP, GD image library, Graphics, Security
a simple pie-chart in php3 (with gd)
Categories : PHP, Graphics, GD image library, Charts and Graphs
Display a bar chart based on random values.
Categories : Graphics, PHP, GD image library, Charts and Graphs
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
Simple PHP Bar Graph using GD library
Categories : PHP, GD image library, Graphics, Arrays
CAPTCHA[Image verification]
Categories : PHP, Security, GD image library, Graphics, Sessions
Add a text description to an image. The text is not created over the image but rather creates a new, higher image. The upper part is the original image and the lower is the text. Text is wrapped at the end of line, the number of rows is adjustable.
Categories : PHP, GD image library, Graphics
Advanced Image WaterMarker
Categories : PHP, PHP Classes, GD image library, Graphics, Object Oriented