0

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

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by EvolutionFallen
1

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');
0

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>

Edited by EvolutionFallen: n/a

0

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" />
0

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!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.