Wednesday, April 4, 2018

Print the text on image using GD library in php


GD library is a graphics drawing library that provides tools for manipulating image data. The GD library is used to process images for generating gallery preview and thumbnail size images automatically.

In php GD library provides the function for display the text on the images .
  The given example to show text data on the image using GD library.
 Certificate Image Before

<?php
$yourname = "Brijpal Singh";
$date = "01 Apr 2018";
$pos = "2018";
$rollNo="1003";
$day="Monday";
$month="Apr";
$year="18";
$fta="FTA";
$code="C001";
$startDate="2018";
$endDate="2020";
$dest = imagecreatefrompng('brij.png');//Link  Of Certificate Image
$src = imagecreatefromjpeg('th.jpg'); // Candidate Image (passport size);
imagealphablending($dest, false);

imagecopymerge($dest, $src, 100, 100, 0, 0, 130, 150, 100);
$red = imagecolorallocate($dest, 150,0, 0);
imagefttext($dest, 17, 0, 160, 72, $red, "open-sans/OpenSans-Regular.ttf", $rollNo);
imagefttext($dest, 17, 0, 1080,85, $red, "open-sans/OpenSans-Regular.ttf", $date);
imagefttext($dest, 20, 0, 540, 454, $red, "open-sans/OpenSans-Italic.ttf", $yourname);
imagefttext($dest, 17, 0, 750, 520, $red, "open-sans/OpenSans-Regular.ttf", $pos);
imagefttext($dest, 17, 0, 400, 585, $red, "open-sans/OpenSans-Regular.ttf", $day);
imagefttext($dest, 17, 0, 650, 585, $red, "open-sans/OpenSans-Regular.ttf", $month);
imagefttext($dest, 17, 0, 880, 585, $red, "open-sans/OpenSans-Regular.ttf", $year);
imagefttext($dest, 17, 0, 450, 645, $red, "open-sans/OpenSans-Regular.ttf", $fta);
imagefttext($dest, 17, 0, 880, 645, $red, "open-sans/OpenSans-Regular.ttf", $code);
imagefttext($dest, 17, 0, 500, 705, $red, "open-sans/OpenSans-Regular.ttf", $startDate);
imagefttext($dest, 17, 0, 980, 705, $red, "open-sans/OpenSans-Regular.ttf", $endDate);

// Output and free from memory
header('Content-Type: image/png');
imagepng($dest);

?>

Output:-





No comments:

Post a Comment

Featured Post

What is JavaScript? What is the role of JavaScript engine?

  The JavaScript is a Programming language that is used for converting static web pages to interactive and dynamic web pages. A JavaScript e...