Part II of adding MySQL Data from table to Image.
To the above script we can add QR code, Photo of students and logo to the certificate.
Download Zip file with script and SQL dump of student table at the end of this tutorial.
Generating certificates using student photo QR code & logo with data from MySQL table using PHP GD
VIDEO Adding QR code
How to add QR code to the certificate is explained in MySQL - QR Part III, the part of the code is here.
imagecopyresampled($img_source, $QR, 475, 40 , 0, 0, 100, 100, 100,100);
Adding student photo
We will keep photos of students in one folder photos( download the zip file at the end of this page with sample photos ) . File name of the photos are same as student id like . 1.jpg, 2.jpg .... This is done to maintain unique photos against each student as there is a possibility that name of two students can be same.
We created the path by using file name with directory name in above code and then by using
imagecopy($img_source,$str, 60, 310 , 0, 0, 100, 100);
imagecopy() the same is added at a location ( x=60, y=310 ) of the source image.
If Logo is common in all certificates then it is better to add the same to main template. However to understand the process of adding images dynamically this code is used.
Above codes are kept inside the for loop used to generate certificates of all students by taking data from
imagecopy($img_source,$str, 280, 50 , 0, 0, 50, 50);
MySQL student table.
Part 1 : How certificate is prepared by using user input through a HTML form
Download the script and sample template ( image ).
File Name Details
config-pdo.php PDO Database connection details are stored here.
gd-certificate.php Php script to Generate the image with data, profile photo and logo for each student.
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
Download Zip File of gd-Certificate4 with sample logo and student photos
How QR code is embedded in Certificate ( image ) using MySQL table data