cc.jpg

Php code to create certificate and export as jpg image

Here is a php code in which the output is a certificate 

Output will be certificate like this.

<?php

$font=realpath(‘arial.ttf’);
$font1 = realpath(‘AbrilFatface-Regular.ttf’) ;
$font2 = realpath(‘Pacifico-Regular.ttf’) ;
$font3 = realpath(‘GreatVibes-Regular.ttf’) ;
$name = “shubham Haldkar” ;

// Get dimensions of new image
list($width, $height) = getimagesize(‘e1.jpg’);

// Reduce width and height to half

$new_height = 100;
$new_width = 100 ;

// Resample the image
$image_p = imagecreatefromjpeg(‘e1.jpg’);
$image = imagecreatefromjpeg(‘format.jpg’);
list($n_width, $n_height)= getimagesize(‘format.jpg’);
$desc =” Lorem ipsum, dolor sit amet consectetur adipisicing elit.
Libero asperiores quam dolorum quod nulla sed doloremque delectus
temporibus ea repellat rem omnis suscipit fugiat, quaerat molestiae ” ;
$h = $n_height/100 ;
$new_width = abs($n_width/$h) ;

imagecopyresampled($image_p, $image, $width-$new_width-20, 20, 0, 0, $new_width, $new_height, $width, $height);

$color1=imagecolorallocate($image_p, 178,34,34);
$color2=imagecolorallocate($image_p, 80,80,80);

imagettftext($image_p, 98, 0, 480, 368, $color1,$font1, “CERTIFICATE”);
imagettftext($image_p, 38, 0, 690, 413, $color1,$font1, “OF ACHIEVEMENT”);
imagettftext($image_p, 78, 0, 200, 563, $color2,$font2, $name);

imagettftext($image_p, 50, 0, 150, 653 , $color2,$font3, $desc);

header(‘Content-Type: image/jpeg’);
imagejpeg($image_p, null, 100);
?>

Description of code

Here we are using image size of certificate is 1754 x 1240 px. You are recommended to use use the same size of image. 
Below is the  folder structure.

Tags: No tags

Leave A Comment

Your email address will not be published. Required fields are marked *