How to Add Text Watermark to Image in 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.

Example:

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.

.medrectangle-3-multi-157{border:none!important;display:block!important;float:none;line-height:0;margin-bottom:15px!important;margin-left:0!important;margin-right:0!important;margin-top:15px!important;max-width:100%!important;min-height:250px;min-width:300px;padding:0;text-align:center!important}

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

index.php

<?php

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

$imagetobewatermark = imagecreatefrompng($sourceImage);

$watermarktext="ITSOLUTIONSTUFF.COM";

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

$fontsize="22";

$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);

header("Content-type:image/png");

/*

For Save Image

imagepng($imagetobewatermark, $sourceImage);

*/

imagepng($imagetobewatermark);

imagedestroy($imagetobewatermark);

Output:

How to Add Text Watermark to Image in PHP?

I hope it can help you….medrectangle-4-multi-155{border:none!important;display:block!important;float:none;line-height:0;margin-bottom:15px!important;margin-left:0!important;margin-right:0!important;margin-top:15px!important;max-width:100%!important;min-height:250px;min-width:300px;padding:0;text-align:center!important}

Leave a Comment