I am a newbie playing around with PHP’s image manipulation scripts. I am trying to get PHP to intergrate with html. The code below is supposed to create an image with text on it. The code works great without any html. e.g. if I have just <?php …. to ?>. However, when I add html it converts the image into “text”, not really what I am looking for.
What am I doing wrong? I assume that PHP can be placed anywhere in the <body> of an html document. FYI, I am using Apache 2.0.54 and PHP 5.0.4. Is there something I need to modify in the config file or .ini file to get this to work?
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
$image = imagecreatefromjpeg(“smp.jpg”);
$text=”test”;
$font=”arial.ttf”;
$fontsize=25;
//choose textcolors (black & white), shadow effect
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
//check width of the text
$bbox=imagettfbbox ($fontsize, 0, $font, $text);
$xcorr=0-$bbox[6];
$mase=$bbox[2]+$xcorr;
//check width of the image
$width=imagesx($image);
//calculate x coordinates for text
$new=($width-$mase)/2;
//write text
imagettftext ($image, $fontsize, 0, $new-4, 60, $black, $font, $text);
imagettftext($image, $fontsize, 0, $new, 60, $white, $font, $text);
//output picture
imagejpeg($image,””,100);
imagedestroy($image);
?>
</body>
</html>