You can add watermark on image using php. PHP uses its GD library to write text on images using true type fonts.
To add a watermark, you need an image and any font with extension ttf. For example image type can be jpg / jpeg, png, gif, wbmp
.
Now function for adding watermark.
<?php function createWatermarkOnImage ($imagePath, $waterMarkText){ header ("Content-type: image/jpeg"); $font = 4; $width = imagefontwidth($font) * strlen($waterMarkText) ; $height = imagefontheight($font) ; $image = imagecreatefromjpeg($imagePath); $x = imagesx($image) - $width ; $y = imagesy($image) - $height; $backgroundColor = imagecolorallocate ($image, 255,255,255); $textColor = imagecolorallocate ($image, 0,0,0); imagestring ($image, $font, $x, $y, $waterMarkText, $textColor); imagejpeg($image); } createWatermarkOnImage ('banner.jpg', 'Datainflow'); ?>
First parameter is path of image and second parameter is text for watermark.
Question and answer is powered by AnsPress.io