Adding form input data to Image

Here is a blank template ( certificate ). Below that there is a form and one sample output is shown.
certificate template

Name
Grade
Name and Grade will be taken from above form and current date with time will be taken from system and added to the image. Add your name and grade here and on submit the certificate with data will be created in a new window.
Here is one sample output
certificate with data

Generating image from a template by adding user entered form data by imagestring() in PHP GD

Script to generate the image by using the blank certificate template and adding data submitted by user through form.
<?Php
header ("Content-type: image/jpg");
 
$name=$_POST['t1'];   // Text to be written on Image. 
$grade=$_POST['s1'];  // Grade to be written 
$x=260; // X - Postion of text. 
$y=205; // Y- Postion of text . 
///// Add Name to the image ////////
$file_name='images/gd-template.jpg'; // Image collected
$img_source = imagecreatefromjpeg($file_name); // Image created
$text_color = imagecolorallocate($img_source, 0, 0, 0);

ImageString($img_source,5,$x,$y,$name,$text_color); //  
/// add grade ////
$x=260; // X - Postion of text. 
$y=250; // Y- Postion of text . 
$text_color = imagecolorallocate($img_source, 255, 0, 0);
ImageString($img_source,5,$x,$y,$grade,$text_color); //  
/// add date ////
$today   = new DateTime;
$str_date=$today->format('Y-M-d H:i:s');

$x=421; // X - Postion of text. 
$y=399; // Y- Postion of text . 
$text_color = imagecolorallocate($img_source, 100, 100, 0);
ImageString($img_source,4,$x,$y,$str_date,$text_color); //  

//ImageJpeg ($img_source,'gd-template2.jpg'); // image saved 
ImageJpeg ($img_source); // image saved 
imagedestroy($img_source); //memory is removed. 
?>
We used one simple HTML form with POST method to submit data. Here is the code.
<form method=post action=gd-certificateck.php class="form-inline">
Name <input type=text name=t1 class='form-control' size=15>
Grade<select name=s1 class='form-control'><option value='A'>A</option>
<option value='B'>B</option><option value='C'>C</option></select>
<input type=submit value=Sumbit class='btn btn-info' 
onclick="this.form.target='_blank';return true;">
</form>
Download the script and sample template ( image ).
File NameDetails
index.html HTML form to enter data by user .
gd-certificate.php Php script to Generate the image with user entered data in the form.
gd-template.jpg The sample template image used to generate the final certificates.
readme.txt Instructions on how to run the script

Using data from MySQL table and generating Certificates dynamically.

We have 35 students in a MySQL table and each record has student name, mark, class , gender and id columns. For all students ID is unique. We will print certificates of each student by using data stored against each student. The script will generate certificates by assigning file name based on the ID of the student. All certificates should be stored inside one folder ( outputs ) and name should be 1.jpg, 2.jpg, 3.jpg etc ..
Adding MySQL table data to Image to generate certificates using GD functions
GD functions

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Applications using GD functions in PHP

    Basic function and application using GD in PHP
    Sin and Cos curve using GD
    Script for Watermarking image on the fly using PHP GD
    Script to generate Captcha using GD with demo
    Getting Image coordinates ( vertical and horizontal ) of points inside a image
    Generating certificates by using templates and user inputs
    Generating certificates by using templates and MySQL table data
    Generating certificates by using templates and MySQL table data with QR code
    Page Hit counter script

    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2021 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer