Add Text to An Image in PHP (Text Watermark)

by Sasikumar 2014-09-05 15:26:56

We can add text to an image in php by using the following code,
PHP Code :

// Set the Content Type
header('Content-type: image/jpeg');

// Create Image From Existing File
$jpg_image = imagecreatefromjpeg('demo_image.jpg');

// Allocate A Color For The Text
$white = imagecolorallocate($jpg_image, 255, 255, 255);

// Set Path to Font File
$font_path = 'my_font.TTF';

// Set Text to Be Printed On Image
$text = "This is a demo on hiox.org";

// Print Text On Image
imagettftext($jpg_image, 25, 0, 75, 300, $white, $font_path, $text);

// Send Image to Browser
imagejpeg($jpg_image);

// Clear Memory
imagedestroy($jpg_image);
633
like
0
dislike
0
mail
flag

You must LOGIN to add comments