header("Content-type: image/jpg");
<?php
header ("Content-type: image/jpg");
///// Create the image ////////
$im = @ImageCreate (100,40)
or die ("Cannot Initialize new GD image stream");
$background_color = ImageColorAllocate ($im, 204, 204, 204); // Assign background color
$text_color = ImageColorAllocate ($im, 51, 51, 255); // text color is given
ImageString($im,5,10,10,'PLUS2NET',$text_color); // Random string from session added
ImageJpeg ($im); // image displayed
imagedestroy($im); // Memory allocation for the image is removed.
?>
Output is here<img src=gd-imagestring-demo.php>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dynamic Image in PHP</title>
</head>
<body>
<h2 class="text-primary">Generated Image from PHP</h2>
<p class="text-muted">The image below is dynamically generated by test1.php.</p>
<img src="test1.php?time=<?php echo time(); ?>" alt="Dynamic Image" >
</body>
</html>
This code dynamically loads an image generated by the test1.php script. The query string ?time=<?php echo time(); ?> appends a unique timestamp to the image URL using PHP's time() function.<img src="https://www.example.com/dir/test1.php?time=<?php echo time(); ?> alt="Dynamic Image" >
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.