Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ctaljaardt's avatar

Generating Certificates with PHP?

How do i Generate a certificate with a users name on it using php/laravel.

I have a customer base, and when they make a purchase, i want to generate a Certificate for them, i have the certificate created in photoshop right now. I want to use php to edit the users name in the name field and the date etc onto the certificate and then email it to the user.

I want to know how i would go around doing such a task?

Thanks

0 likes
7 replies
kfirba's avatar

@ctaljaardt You can use native PHP functions to do so:

$path = 'path/to/template.jpg';
$image = imagecreatefromjpeg($path);

$color = imagecolorallocate($image, 255, 255, 255);
$string = 'The string you want to write horizontally on the image';
$fontSize = 3;
$x = 300;
$y = 400;

// write on the image
imagestring($image, $fontSize, $x, $y, $string, $color);

// save the image
imagejpeg($image,  $fileName = 'path/to/save/the/image', $quality = 100);
Hamelraj's avatar

I hopeYou have to create certificate as a PDF install this in your project - https://github.com/barryvdh/laravel-dompdf in your controller do like this this sample of creating invoice ok

public function invoice($id){
        $job = Job::find($id);
 $pdf = \PDF::loadView('jobs.invoice',compact('job'));
        return $pdf->download('invoice.pdf');

in my index i have all the jobs in a table when i click invoice button i can generate my invoice same like you also can do yours this is how i call invoice method

<td>
<a href="{!! action('JobsController@invoice',$job->id) !!}" >
<button class="btn btn-orange btn-xs">
      <i class="fa fa-th-list fa-fw"></i>
</button></a>
</td>

if you need any help try your code update then we can help you

ctaljaardt's avatar

Hello,

@Hamelraj

I have tried this method and its not working, i posted an issue in the Github which can be found here : https://github.com/dompdf/dompdf/issues/1093

I tried what they said with the tags to get it rendered but its still not working.

I don't know what else to do.

Right now the Certificate is a PSD file, i can export it as SVG and then edit the text within the code of the SVG because its plain text, but i cant render the SVG file for some reason.

Hamelraj's avatar

@ctaljaardt listen as your mention if you have a file test.blade.php insight cert folder useroute like this then in your url yourprojectname/certificate you will get blank PDF file then if you want paas the data you follow method what i have mention before careful cert.test means cert folder test.blade.php file and when you create Controller remember use camel case its good

Route::get('certificate',TestController@testfunction);
kunleadeoye's avatar

Hello, has anybody here got a solution to this with Laravel?

Snapey's avatar

@kunleadeoye plenty of solutions listed. This is a 4 year old question start your own if you have a problem.

Please or to participate in this conversation.