0

I want to add user input (input text box) to an image using php code. I will be highly grateful, in-case someone be of help to me. In below code I am trying to add static code, but it's still not writing on image.

<html>
<body>
<?php header('Content-type: image/jpeg'); ?>
<div style="padding-left:10px;width:575px; height:350px;background-color:yellow;">
<form action="" method="post">
<table style="border: 1px solid black;border-collapse: collapse;">
    <tr>
    <td style="border: 1px solid black;">Name:>
    <td style="border: 1px solid black;">  
    <input style="width: 300px;" name="name" type="text"></input>
    <input name="submit" type="submit" value="Submit" />
    </td>
    </tr>
</table>
</form>
<?php
$jpg_image = imagecreatefromjpeg('E:\structure.jpg');
  $color = imagecolorallocate($jpg_image, 255, 255, 255);
    $font_path = 'C:\Windows\Fonts\cambria.ttc';
  // Set Text to Be Printed On Image
  $text1 = "Hi Ujjwal Joshi,";
  $text = "Good Morning";
  imagettftext($jpg_image, 18, 0, 75, 100, $color, $font_path, $text1);
  imagettftext($jpg_image, 18, 0, 100, 175, $color, $font_path, $text);
  imagejpeg($jpg_image);
  imagedestroy($jpg_image);
?>
</div>
</body>
</html>
chris85
  • 23,846
  • 7
  • 34
  • 51
Ujjwal
  • 1
  • `Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.` http://php.net/manual/en/function.header.php – chris85 Jul 27 '15 at 19:15
  • You're mixing things all together. That's not how it works. You can't send headers after you have echoed content. Then you need to actually echo the image to the browser somehow. – Mike Jul 27 '15 at 19:15
  • Errors in error log? You can't have output before any header and that is a html page, why are you sending `content-type: image/jpeg` header ? – frz3993 Jul 27 '15 at 19:16

0 Answers0