Thursday, May 7, 2009

Watermarking on Images

One of the things you can do with PHP's many functions for image handling and manipulation is create an image watermarking class. This will allow you to add a watermark to images, which can be useful for a number of purposes.PHP features a wide array of functions for image handling and manipulation.

The main important of watermarking the image is to protect the images in a particular site. We may have the important images displayed and we donot want to redistribute the images to any other web sites. For such type of tasks the watermarking class is the best solution.

Through the watermarking we can restrict the image by placing our website name on the image and show the image while displaying to the user.One more thing that we need to save the watermarking and display, Just at the time of displaying the image we will make the image to be displayed by placing the watermarking text, By doing this we can have the original image with us and protect the image displayed to the user end as we imagecreatetruecolorare watermarking the image with the website name.

The main function used for creating the class is:

watermarkImage
This function takes the 3 parameters source file , destination file and the watermark text. if you want to save the file then you need to give the desitnation file path of not you can just simply leave it by empty paratemers.

imagesx outputs the width of the image.

imagesy outputs the height of the image.

imagecopyresampled copies a rectangular portion of one image to another image, smoothly interpolating pixel values so that, in particular, reducing the size of an image still retains a great deal of clarity.

imagettftext rites the given text into the image using TrueType fonts.

imagecreatetruecolorreturns an image identifier representing a black image of the specified size

imagejpegcreates a JPEG file from the given image .

There is a small difference between the imagejepg function

// Output the image
imagejpeg($im);

// Save the image as 'simpletext.jpg'
imagejpeg($im, 'simpletext.jpg');

if 1 parameter is provided then it directly shows the image and if you provide the file name then it saves the image with that particular file name.

Preview:



Leia Mais…