KidsLovePC Contact Us
  Home   PHP  Graphics ASP  JavaScript   J2EE  HTML  JAVA   Swing   Webtip  Forums  Lyric  Free sheet music  Ringtones

Put water mark on image-Image processing in PHP

Before you start this lesson, before read the lesson PHP Image processing introduction and make sure you enable GD library.

This tutorial will demonstrate how to put water mark on image.

Image Requirement

First you need 2 images, one is water mark image, the other one is the image you want to process.

We select a transparent .gif image for water mark and .png image for the background image.

Here is the code to put water mark on image in PHP.

// Transparency, 100 for none, 0 for not visible
$WaterMark_Transparency = "50";

// Import the images to use...
// the watermark is a gif (transparency without the white.)

$WaterMark = imageCreateFromGIF("water.gif");
$Main_Image = imageCreateFromPNG("pig.png");

// Get the width and height of each image.
$Main_Image_width = imageSX($Main_Image);
$Main_Image_height = imageSY($Main_Image);
$WaterMark_width = imageSX($WaterMark);
$WaterMark_height = imageSY($WaterMark);

// calculate the position of the WaterMark
$MaterMark_x = ($Main_Image_width - $WaterMark_width);
$MaterMark_y = ($Main_Image_height - $WaterMark_height);

//put the watermark on top of the background image.
imageCopyMerge($Main_Image, $WaterMark, $MaterMark_x, $MaterMark_y, 0, 0, $WaterMark_width, $WaterMark_height, $WaterMark_Transparency);

// Let the browser know that it is an image..
header("Content-Type: image/PNG");

// show the image in png format(sharper image)
ImagePNG ($Main_Image);

Processed Image example

Water mark:php image processing, water  mark

Background Image:

php image processing, water  mark

Image processed:

php image processing, water  mark


Warning: mysql_connect(): Access denied for user 'kidslove'@'localhost' (using password: YES) in /home1/chinesel/public_html/kidslovepc/php-tutorial/pullcom2.php on line 9
Unable to specified database