watermark in php example with code

72

Adding watermark in PHP is very simple. It can be done using PHP image libraries like GD. Using GD functions, we can use text or image as watermark onto a target layer/document.

PHP / GD Text Watermarking

Text watermarking functions are,

  • imagestring() – Adding text string into images
  • imagettftext() – Adding text into images using True Type Fonts

Syntax:

The imagestring() function is sufficient for adding simple watermark without more gimmicks. To add effects like angled text as watermark, imagettftext() function can be used. It provides a rich set of effects.

There are more GD functions to add text watermark to images using other font types Free Type and Post Script Type. For example, imagefttext(), imagepstext().

PHP / GD Text Watermarking Example

PHP / GD Image Watermarking

In PHP, adding an image onto another image layer as a watermark can be done using imagecopy() function.

This function copies source image onto destination image by overwriting destination image pixels.

There is another similar GD function imagecopymerge() which is to copy and merge source onto the destination.

imagecopymerge() function has an extra parameter $pct. It is used for image merging.

While merging png images with transparent background as a watermark, imagecopymerge() function will not preserve transparency onto the destination. So, imagecopy() is preferable for image watermarking.

PHP / GD Image Watermarking Example

 

Leave A Reply

Your email address will not be published.