In this tut i will explain you that how we can prevent or best capture image from the people who download your image and sell it over internet and you never know who do this. To prevent your image from this we have solution, we create a copyright watermark over image. But the standard watermarking procedure of editing the image in a photo-editing application is time consuming. And we dont have so much time to do this. PHP offers a far better solution to solve this problem and save your time.

 

PHP 4+ and GD 2.0+ represent a powerful combination when it comes to creating or altering images dynamically. We print a transparent gif-image on a jpeg-photo. To achive best result i prefer you to use Gif format image watermark as compare to PNG.

Now first we can create PHP Code to create a text watermark over image

Text watermark Code

In the above code i create a small function textwatermark(“image source”, “watermark text”, “save location”) and pass three parametter inside it.

  1. First we get width and height of source image.
  2. Use php GD function imagecreatetruecolor();.
  3. Use php function to create image from jpeg.
  4. then re sample image using imagecopyresampled().
  5. then we use collor allocation function imagecolorallocate().
  6. In this i am also using font family ‘monofont.ttf’.
  7. Use imagettftext() to add text over image.
  8. Now we use header() to tell the Web browser that we are going to output an image in JPEG format.

Image Watermark Code

Now we add GIF watermark image over Image.

In above code most of functions are same we use in text watermark and one new function i use in this is imagecopymerge() to merge watermark over image we also declaire opacity in it.

Thanku!!