I have looked everywhere for an answer to this and am constantly frustrated in the process! Is there anyone who can help please?
I understood that having created an image with php it was possible to load it using the img tag and it certainly works where the comment is hard coded. But as soon as I get the comment from input from the user all I get is a placeholder instead of the image.
I have the following html file to gather comments from users:
<html>
<head><title>myscripthtml</title>
<script type="text/javascript">
function getComments()
{
return true;
}
</script>
</head>
<body>
Provide comments
<form name="cmt" action="myscript2.php" method="GET" onSubmit="return getComments()"/>
<input type="text" name="cmment"/>
<input type="submit" value="submit comments"/>
</form>
</body>
</html>
The following ‘myscript2.php’ file creates an image BUT I can’t get that image to load using the img tag:
<img src=”myscript2.php”/>
<?php
// Path to our font file
$font = 'arial.ttf';
$fontsize = 10;
$quotes = $_GET['cmment'];
// get the quote and word wrap it
$quote = wordwrap($quotes,20,"<br />\n");
// Create image
$image = imagecreatefrompng('baseimage.png');
// pick color for the background
$bgcolor = imagecolorallocate($image, 100, 100, 100);
// pick color for the text
$fontcolor = imagecolorallocate($image, 255, 255, 255);
// fill in the background with the background color
imagefilledrectangle($image, 200, 100, 400, 200, $bgcolor);
// x,y coords for imagettftext defines the baseline of the text: the lower-left corner
// so the x coord can stay as 0 but you have to add the font size to the y to simulate
// top left boundary so we can write the text within the boundary of the image
$x = 0;
$y = $fontsize;
imagettftext($image, $fontsize, 0, $x, $y, $fontcolor, $font, $quote);
// tell the browser that the content is an image
header('Content-type: image/png');
// output image to the browser
imagepng($image);
// delete the image resource
imagedestroy($image);
?>
Surely there is a way to do this but I am unable to uncover it.
Thanks