Reputation: 4603
I feel quite stupid but I can't understand how to display the output of the imagepng() function.
What I currently do is (and it works fine) :
<img src=<?php echo getImage($element); ?> />
function getImage($element){
return $bdd[$element]; // the result is a string with the path to the image
}
But I would love to draw some circles on the image, so here is what I would like to do (and it does not work) :
<img src=<?php echo getImage($element); ?> />
function getImage($element){
$image = imagecreatefrompng($bdd[$element]);
$ellipseColor = imagecolorallocate($image, 0, 0, 255);
imagefilledellipse($image, 100, 100, 10, 10, $ellipseColor);
imagepng($image);
return $image // why does that image resource not display ?
}
But it does not display anything else than symbols.. I assume it returns a full image and not a path to the image.. so How should I display my image with the circle on it ?
ps : I also tried to create a page getImage.php that would be called by <img src=<?php echo 'getImage.php?element=' . $element; ?> />
but with no success
Upvotes: 3
Views: 3938
Reputation: 1079
You have to do something like this
<img src="image.php">
And in the image.php you use your code
$image = imagecreatefrompng($bdd[$element]);
$ellipseColor = imagecolorallocate($image, 0, 0, 255);
imagefilledellipse($image, 100, 100, 10, 10, $ellipseColor);
imagepng($image);
Upvotes: 3
Reputation: 4603
I finally got my answer on how to display the image inside an HTML page :
I need to put the code in another file displayImage.php
and make a call to this page from the <img>
tag :
Main file with html tag:
<img src="displayImage.php?element='<?php echo $element; ?> />
displayImage.php :
<?php
header('Content-Type: image/png');
$image = imagecreatefrompng($bdd[$element]);
$ellipseColor = imagecolorallocate($image, 0, 0, 255);
imagefilledellipse($image, 100, 100, 10, 10, $ellipseColor);
imagepng($image);
imagedestroy( $image );
?>
Upvotes: 1