PHP
--
Questions
--
Followers
Top Experts
So far I have tried this to test whether gd2 support is set up.
echo function_exists('gd_info')
phpinfo(); Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // gd section had gd support enabled.
So I'm Assuming I have it installed correctly.
This is my first attempt with working with images with php so any help would be much appreciated.
<?php
// Set up the image.
$height = 200;
$width = 200;
$im = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($im, 255, 255, 255);
$blue = imagecolorallocate($im, 0, 0, 64);
// Draw on the Image.
imagefill($im, 0, 0, $blue);
imageline($im, 0, 0, $width, $height, $white);
imagestring($im, 4, 50, 150, 'Sales', $white);
// Output image
Header ('Content-type: image/png');
imagepng ($im);
// Clean up
imagedestroy($im);
?>
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Do you get any output? Are there any messages in your PHP error log?
Could this be something to do with the header location. I have tried to put it at the top of the page but this did not work.
Here is the complete page:
<?php
// I have tried to put the header here and it did not work.
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php
// I have also tried to put the header here and it did not work.
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<title>Generating Images</title>
<link rel="stylesheet" type="text/css" href="" />
<script type="text/javascript" src=""></script>
</head>
<body>
<div id="header">
</div>
<div id="container">
<div id="content">
<?php
// Set up the image.
$height = 200;
$width = 200;
$im = imagecreatetruecolor($width, $height);
$white = imageColorAllocate($im, 255, 255, 255);
$blue = imageColorAllocate($im, 0, 0, 64);
// Draw on the Image.
imagefill($im, 0, 0, $blue);
imageline($im, 0, 0, $width, $height, $white);
imagestring($im, 4, 50, 150, 'Sales', $white);
// Output image
Header ('Content-type: image/png'); // The header I have tried in other locations at top of page
imagepng ($im);
// Clean up
imagedestroy($im);
?>
</div>
<div id="navCol">
</div>
<div id="footer">
</div>
</div>
</body>
</html>
1 sec and I clean it up for you.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
The image "http://localhost/php_sandbox/ch22/"Â cannot be displayed, because it contains errors.
<img src="image.php?var=somethi
$imgfile = getcwd() . 'my.png';
imagepng ($im, $imgfile);
echo "<img src=\"my.png" />\n";

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
PHP
--
Questions
--
Followers
Top Experts
PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.