How to Add Text Watermark to Image in PHP?

By Hardik Savani May 16, 2022 Category : PHP

Hi Dev,

This simple article demonstrates of php add watermark text to image. you will learn how to add watermark text to image in php. I would like to show you php add text on image as watermark. I explained simply about add text watermark to image php. Alright, let’s dive into the steps.

Sometimes we want to add a website domain name as a watermark on each image of your website. Then I will give you a very simple example of how to add a text watermark to image in PHP. so let's simply follow below code and make it done.


Here, You need to put one image call "watermark-php-text.png". Then you have to download font from google fonts and put in folder. You can download from here: Download Font.

Let's copy below code and create index.php file.



$sourceImage = "watermark-php-text.png";

$imagetobewatermark = imagecreatefrompng($sourceImage);


$font= "fonts/Roboto/Roboto-Bold.ttf";


$white = imagecolorallocate($imagetobewatermark, 51, 102, 0);

$image = imagecreatefrompng($sourceImage);

$imageSize = getimagesize($sourceImage);

$wmX = $imageSize[0] - 380;

$wmY = $imageSize[1] - 20;

imagettftext($imagetobewatermark, $fontsize, 0, $wmX, $wmY, $white, $font, $watermarktext);



For Save Image

imagepng($imagetobewatermark, $sourceImage);





I hope it can help you...

Tags :