Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
March 19, 2022 04:29 pm GMT

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 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 Typeheader('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 Browserimagejpeg($jpg_image);// Clear Memoryimagedestroy($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

Thats 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:)


Original Link: https://dev.to/readymadecode/create-dynamic-certificates-in-php-1k89

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To