ID Card printing with php and sql

883 views Asked by At

For context, I'm a begginer web developer and I'm currently working on building a school system using a simple CRUD interface and database connections. Most of the system is complete and I am now working on some way to mass print ID cards for each of the students however I having a hard time fetching the img from the database.

Giving more details about the DB, it was determinated that we would store the img directly into it, even though i've seen it isn't the best method to do it. Also the img is stored in a BLOB cell.

Here it is a sample of he code i've made so far:

<?php
header("content-type: image/jpg");
include 'config-pdo.php';
$file_name='template.jpeg';
require 'config-pdo.php';
$sql="SELECT * FROM student";
foreach($dbo->query($sql) as $row){
    $x=180;
    $y=440;
    $img_source=imagecreatefromjpeg($file_name);
    
    // The idea is to use imagecopy() or something like that and fetch
    // the picture inside the database.
    // Using the id and the loop to garantee that it will be the 
    // correct pic.
    $text_color=imagecolorallocate($img_source,0,0,0);

    ImageString($img_source,5,$x,$y,$row['name'],$text_color);


    imagejpeg($img_source,"outputs/$row[id].jpg");
    imagedestroy($img_source);
}
?>
0

There are 0 answers