GD library :- Write text over the image





<?php
header('Content-type: text/html; charset=UTF-8');
include("config.php");
$result = mysql_query("SET NAMES utf8");
$query = ("SELECT * FROM `field_data_body`");
$result=mysql_query($query);
while($row = mysql_fetch_array($result))
{
    $fromdb = $row['body_value'];
    $id = $row['entity_id'];
    $text = strip_tags($fromdb);

$newtext = wordwrap($text, 25, "\n", false);

$image = imagecreatefrompng('selfie_baba.png');
imagealphablending($image, true);

$color = imagecolorallocate($image, 0,0, 0);

$font='font/OpenSans-Semibold.ttf';


// imagefttext("Image", "Font Size", "Rotate Text", "Left Position", "Top Position", "Font Color", "Font Name", "Text To Print");

  imagefttext($image, 40, 0, 60, 200, $color, $font, $newtext);

/* If you want to display the file in browser */
//header('Content-type: image/png');
//ImagePng($image);
//imagedestroy($image);


/* if you want to save the file in the web server */

/*
$filename = 'certificate_aadarsh.png';
ImagePng($image, $filename);
imagedestroy($image);
*/

/* If you wnat the user to save the file */

/*
$filename = 'certificate_aadarsh.png';
ImagePng($image,$filename);

header('Pragma: public');
header('Cache-Control: public, no-cache');
header('Content-Type: application/octet-stream');
header('Content-Length: ' . filesize($filename));
header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
header('Content-Transfer-Encoding: binary');
readfile($filename);

imagedestroy($image);

*/

 $rand_no = date('Y-m-d H-i-s');
 $rand_no = str_replace(' ', '', $rand_no);
 $rand_no = str_replace('-', '', $rand_no);
 $filename ='selfie_baba_'.$rand_no.$id.'.png';

//$filename = 'selfie_baba.png';
ImagePng($image,'image/'.$filename);
imagedestroy($image);
}
?>

First