I just downloaded and installed xampp on my xp machine. I'm quite new to Apache, PHP and web development in general. Although, I've done a few projects way back in college.
Anyways.. I'm trying to use GD which I understand is already bundled with PHP. I checked php.ini and found that php_gd2.dll is set as an extension (no comment out). the dll file also exists.
Im trying to run this code from http://www.php.net/manual/en/function.imagejpeg.php but I get a blank page. Am I using it wrong?
- Code: Select all
<html>
<body></body>
<?php
// Create a blank image and add some text
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
// Set the content type header - in this case image/jpeg
header('Content-type: image/jpeg');
// Output the image
imagejpeg($im);
// Free up memory
imagedestroy($im);
?>
</html>
the output html is this
- Code: Select all
<html>
<body style="margin: 0px;">
<img style="-webkit-user-select: none" src="http://localhost/test/">
</body>
</html>
If I change the code to include the optional filename parameter a file is generated.
- Code: Select all
imagejpeg($im,"test.jpg");
Should I just generate an image and write down <img> tags to reference to that file?
Thanks!