An Interest In:
Web News this Week
- March 22, 2024
- March 21, 2024
- March 20, 2024
- March 19, 2024
- March 18, 2024
- March 17, 2024
- March 16, 2024
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();
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
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To