Adding photo and logo with Data to create Image

certificate with photo and logo

To the above script we can add QR code, Photo of students and logo to the certificate.

Generating certificates using student photo QR code & logo with data from MySQL table using PHP GD

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.
$QR=imagecreatefromstring(file_get_contents(
  "https://chart.googleapis.com/chart?chs=100x100&cht=qr&chl="
  .urlencode($row->id)));
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.
$str=imagecreatefrompng("photos/".$row[id].".png");
imagecopy($img_source,$str, 60, 310 , 0, 0, 100, 100);
We created the path by using file name with directory name in above code and then by using imagecopy() the same is added at a location ( x=60, y=310 ) of the source image.

Adding Logo

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.
$str=imagecreatefrompng("logo.png");
imagecopy($img_source,$str, 280, 50 , 0, 0, 50, 50);
Above codes are kept inside the for loop used to generate certificates of all students by taking data from 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 NameDetails
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

How QR code is embedded in Certificate ( image ) using MySQL table data
GD functions
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com











    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 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer