Create dynamic certificates in PHP

We will use the PHP GD Library or extension which will provide us the functions to manipulate our images dynamically.

Uses of PHP GD Library:

To create dynamic certificates
Create dynamic captcha
Creating dynamic charts
Creating dynamic Re…


This content originally appeared on DEV Community and was authored by Chetan Rohilla

We will use the PHP GD Library or extension which will provide us the functions to manipulate our images dynamically.

Uses of PHP GD Library:

  • To create dynamic certificates
  • Create dynamic captcha
  • Creating dynamic charts
  • Creating dynamic Reports
  • We can create the watermarks on our images
  • We can resize the images, increase or decrease the quality of images, change image mime type or extension
  • Optimize or Compress Images

Here we will create a dynamic certificate in PHP by using PHP GD Library.

First of all we have to check is PHP GD Extension is enabled or not. Use the code below and check is gd enabled.

<?php

/*Checking the PHP GD Extension Enabled or Not*/

phpinfo();

PHP Info

Now we will create the certificate dynamically by using php gd library.

/*Using PHP GD Library to process images and creating dynamic certificates, captcha, reports etc.*/

/*Creating Certificate Dynamically*/

//Set the Content Type
header('Content-type: image/jpeg');

// Create Image From Existing File
$jpg_image = imagecreatefromjpeg('certificate.jpg');

// Allocate A Color For The Text
$white = imagecolorallocate($jpg_image, 54, 12, 110);

// Set Path to Font File
$font_path = 'font.ttf';

$name_text = "Chetan Rohilla";

$date_text = date('jS F,Y');

$signature = imagecreatefrompng('signature.png');

imagettftext($jpg_image, 26, 0, 480, 400, $white, $font_path, $name_text);

imagettftext($jpg_image, 20, 0, 220, 670, $white, $font_path, $date_text);

/*signature on image*/
imagecopy($jpg_image, $signature, 780, 620, 0, 0, 200, 58);
/*signature on image*/

// Send Image to Browser
imagejpeg($jpg_image);

// Clear Memory
imagedestroy($jpg_image);

After adding this code, you have to upload certificate.jpg file, signature.png file and font.ttf file in the folder where your php file is located.

Download font.ttf

That’s it Now you can create dynamic certificates in php, watermarks in php, captcha in php, charts in php or process images in php.

Please like share subscribe and give positive feedback to motivate me to write more for you.

For more tutorials please visit my website.

Thanks:)
Happy Coding:)


This content originally appeared on DEV Community and was authored by Chetan Rohilla


Print Share Comment Cite Upload Translate Updates
APA

Chetan Rohilla | Sciencx (2022-03-19T16:29:30+00:00) Create dynamic certificates in PHP. Retrieved from https://www.scien.cx/2022/03/19/create-dynamic-certificates-in-php/

MLA
" » Create dynamic certificates in PHP." Chetan Rohilla | Sciencx - Saturday March 19, 2022, https://www.scien.cx/2022/03/19/create-dynamic-certificates-in-php/
HARVARD
Chetan Rohilla | Sciencx Saturday March 19, 2022 » Create dynamic certificates in PHP., viewed ,<https://www.scien.cx/2022/03/19/create-dynamic-certificates-in-php/>
VANCOUVER
Chetan Rohilla | Sciencx - » Create dynamic certificates in PHP. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/03/19/create-dynamic-certificates-in-php/
CHICAGO
" » Create dynamic certificates in PHP." Chetan Rohilla | Sciencx - Accessed . https://www.scien.cx/2022/03/19/create-dynamic-certificates-in-php/
IEEE
" » Create dynamic certificates in PHP." Chetan Rohilla | Sciencx [Online]. Available: https://www.scien.cx/2022/03/19/create-dynamic-certificates-in-php/. [Accessed: ]
rf:citation
» Create dynamic certificates in PHP | Chetan Rohilla | Sciencx | https://www.scien.cx/2022/03/19/create-dynamic-certificates-in-php/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.