Using Data from MySQL with ImageString() to create Image

Here is a blank template ( certificate ).
certificate template

By using this template we will generate certificate for each student by using their data from MySQL student table. Here is one sample output
certificate with MySQL table student data

Part 1 : How certificate is prepared by using user input through a HTML form

Generating certificates using standard templates by adding data from MySQL table using PHP GD

Getting records from MySQL database

We are using Php Data Object ( PDO ) to connect to database and getting the records by using looping. We can use MySQLi also.

There are 35 records in our student table. We will loop through the records by using foreach() and inside the loop we will create the certificates by using the data of each student.
require 'config-pdo.php'; // Database connection object
/// collect data from student table ///
$sql="SELECT * FROM student";

foreach($dbo->query($sql) as $row){
	// generating certificates using each student record.
The full code is here.
header("content-type: image/jpg");
$file_name='gd-template.jpg'; // file using standard template
require 'config-pdo.php'; // database connection details 
/// collect data from student table ///
$sql="SELECT * FROM student LIMIT 0,5 ";

foreach($dbo->query($sql) as $row){
$x=200; // Horizontal position to add name
$y=200; // vertical position to add name

/// adding name ////

$y=230; // vertical position to add class 

$y=260; // vertical position to add mark 

$y=290; // vertical position to add gender 

$x=60; // Horizontal position to add unique id
$y=399; // vertical position to add unique id

// adding date and time ///
$x=421; // Horizontal position 
$y=399; // vertical   position 
$today=new DateTime; // date object 
$str_date=$today->format('d-m-Y H:i:s');
// end ///
Download the script and sample template ( image ).
File NameDetails
config-pdo.php PDO Database connection details are stored here.
gd-certificate.php Php script to Generate the image with data from MySQL student table.
gd-template.jpg The sample template image used to generate the final certificates.
sql_dump.txt SQL Dump to create student table with sample data.
readme.txt Instructions on how to run the script

Adding QR code to certificate

Each student is identified by its unique ID column. Using this unique ID we can create one unique QR code and add the same to each certificate. We can display the certificate with QR code or provide a link to download the certificate as JPG file.
How QR code is embedded in Certificate ( image ) using MySQL table data

Adding Logo, QR code and profile photo to image
GD functions
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net


    I'm using windows 11, mysql, php, html. Graphs format and are drawn ok full screen. However, when I minimze my window the graph remains fullscreen size???? Is there a way to fix this so my graphs will display correctly for all devices.


    This script is generating image only, using the same we can add our CSS ( style ) to make it responsive. The style code required to make it rsponsive can be added while displaying if you are dynamically showing the image. One sample is here
    <img scr=our_image.jpg class='my_rosponsive_style'>
    You can also update the width and height of the template used to generate different size image.

    Post your comments , suggestion , error , requirements etc here

    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer