Hi,
I'm using GD to dynamically draw a rectangle on an image I have of a map. I've got that part working fine.

Here's my question:
I know I need to set the headers of the page to content-type: image/png , otherwise I get a bunch of characters instead of the picture.
But what if I want to place this dynamically created image inside a PHP or HTML document so that I can place text and other data around it? Is there any way to do this, or does the GD-generated image have to stay on its own page?

Thanks
- EF

If you want to place it dynamically inside another page you would have one PHP file generate the image and then point to that in an <img> tag.

But to set the content-type just use:

header('Content-Type: image/png');

I'm clear on how to set the content-type header. My problem is that I don't want to save the dynamically created image. Here's an example of what I'm trying to accomplish.

Dynamic image creation:

<?php
	// File: image.php
	// Description: Displays the map and highlights the appropriate aisle
	header("content-type: image/png");
	
	$mapimg = @imagecreatefromgif('3fl-stacks.gif') or die("Cannot initialize new GD image stream");
	$hl_color = imagecolorallocate($mapimg, 255, 255, 0);
	imagefilledrectangle($mapimg, 300, 300, 350, 310, $hl_color);
	imagegif($mapimg);
	image_destroy($mapimg);

?>

Website to display the image:

<!-- File: index.php -->

<body>
<!-- Dynamically created image should appear here -->
<p class="caption">Description of image</p>
</body>
</html>

Exactly, like I said. You would have one file say image.php generate the image and in the file you wanted to show the image you'd do

<img src="image.php?someparam=somevalue" />

Oh, great! For some reason I didn't think I could put the php file as the src value of the img tag. No idea why. Thanks Shawn!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.