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

    Applications using GD functions in PHP

    Basic function and application using GD in PHP
    Sin and Cos curve using GD
    Script for Watermarking image on the fly using PHP GD
    Script to generate Captcha using GD with demo
    Getting Image coordinates ( vertical and horizontal ) of points inside a image
    Generating certificates by using templates and user inputs
    Generating certificates by using templates and MySQL table data
    Generating certificates by using templates and MySQL table data with QR code
    Page Hit counter script

    Post your comments , suggestion , error , requirements etc here

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