Here is a blank template ( certificate ). Below that there is a form and one sample output is shown.
Name and Grade will be taken from above form and current date with time will be taken from system and added to the image. Add your name and grade here and on submit the certificate with data will be created in a new window. Here is one sample output
Generating image from a template by adding user entered form data by imagestring() in PHP GD
Script to generate the image by using the blank certificate template and adding data submitted by user through form.
<?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.
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
Using data from MySQL table and generating Certificates dynamically.
We have 35 students in a MySQL table and each record has student name, mark, class , gender and id columns. For all students ID is unique. We will print certificates of each student by using data stored against each student. The script will generate certificates by assigning file name based on the ID of the student. All certificates should be stored inside one folder ( outputs ) and name should be 1.jpg, 2.jpg, 3.jpg etc. Adding MySQL table data to Image to generate certificates using GD functions ← GD functions ← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com
✖
We use cookies to improve your browsing experience. . Learn more