We generate a coupon code image as example. Here $couponCode is the variable we can change it as we required. And function createImage() is the main part of this task.

<?php  
 $couponCode = 'A153S0C' ;  
 createImage($couponCode);  
 function createImage($couponCode)  
         {  
         header("Content-type: image/png");  
         /* Set the size of Images */  
         $im = imagecreatetruecolor(400, 400);  
         /* Background Image */  
         $imgBuf = imagecreatefrompng('http://192.168.1.15/texttoimg/image/couponBack.png');  
         imagecopy ($im,$imgBuf,0,0,0,0,400,400);  
         /* For text color Blue */  
         $txtColor = imagecolorallocate($im, 5, 5, 5);  
         /* Font Style */  
         $fontStyle = 'image/fonts/RitzFLF.ttf';  
         /* Give Some Shadow to the text */  
         $shadowColor = imagecolorallocate($im, 128, 128, 128);  
         imagettftext($im, 30, 0, 111, 251, $shadowColor, $fontStyle, $couponCode);  
         /* PLASED THE IMAGE USING PARAMETERS */  
         imagettftext($im, 30, 0, 110, 250, $txtColor, $fontStyle, $couponCode);  
         imagepng($im, "image/couponImg.png");  
         imagedestroy($im);  
         return false;  
         }  
 ?>