I found this code for converting text-to-image and I wanted to echo the result
<?php
// Set the content-type
header('Content-type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
for example I saved that code to image.php, I can echo that image by
echo"<img src='image.php'>";
but I don’t want to do that way, because if I did, I cant assign variable text.
Is there any other way to print the image from that code?
in your image.php
replace
with
and your code to print
Hope this is what you want?
EDIT:
in your image.php file instead of
use