

<?Php
header ("Content-type: image/jpg");
$name=$_POST['t1']; // Text to be written on Image.
$grade=$_POST['s1']; // Grade to be written
$x=260; // X - Postion of text.
$y=205; // Y- Postion of text .
///// Add Name to the image ////////
$file_name='images/gd-template.jpg'; // Image collected
$img_source = imagecreatefromjpeg($file_name); // Image created
$text_color = imagecolorallocate($img_source, 0, 0, 0);
ImageString($img_source,5,$x,$y,$name,$text_color); //
/// add grade ////
$x=260; // X - Postion of text.
$y=250; // Y- Postion of text .
$text_color = imagecolorallocate($img_source, 255, 0, 0);
ImageString($img_source,5,$x,$y,$grade,$text_color); //
/// add date ////
$today = new DateTime;
$str_date=$today->format('Y-M-d H:i:s');
$x=421; // X - Postion of text.
$y=399; // Y- Postion of text .
$text_color = imagecolorallocate($img_source, 100, 100, 0);
ImageString($img_source,4,$x,$y,$str_date,$text_color); //
//ImageJpeg ($img_source,'gd-template2.jpg'); // image saved
ImageJpeg ($img_source); // image saved
imagedestroy($img_source); //memory is removed.
?>
We used one simple HTML form with POST method to submit data. Here is the code.
<form method=post action=gd-certificateck.php class="form-inline">
Name <input type=text name=t1 class='form-control' size=15>
Grade<select name=s1 class='form-control'><option value='A'>A</option>
<option value='B'>B</option><option value='C'>C</option></select>
<input type=submit value=Sumbit class='btn btn-info'
onclick="this.form.target='_blank';return true;">
</form>
Download the script and sample template ( image ).
| File Name | Details |
|---|---|
| index.html | HTML form to enter data by user . |
| gd-certificate.php | Php script to Generate the image with user entered data in the form. |
| gd-template.jpg | The sample template image used to generate the final certificates. |
| readme.txt | Instructions on how to run the script |
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.