For instance, the following script works fine without html
<html><head></head><body><?php $im = imagecreatetruecolor(100, 100);// sets background to red
$red = imagecolorallocate($im, 255, 0, 0);
imagefill($im, 0, 0, $red);

header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?></html>
How could we include a php gd library into html?

Doesn't it have something to do with that when you are using just php then you view an image in a browser? Meaning that you use it as a picture viewer just as you would if you were to right click (windows) on a picture on your desktop and choose "open with... firefox". What I believe you are doing now is trying to make a html-document store image information which it cannot. You must first create the image somewhere on the server through the php script you are using and then afterwards include the image path to that image into an img-element in your html document. Something like this:

<img src="<?php createImageAndReturnImagePath(); ?>" alt="image" />

Then I believe it will show correctly. Remember that this is my guess, I haven't tried your code and actually seen what is happening :)

I am interested if it is possible to create that image, with Gd library, into a php document containing also html code. So, document extension must be .php.
If not, the image could be included like <img src="image.php" >, but I'm not interested.

If that is the case then I believe you can't. The aforementioned way is that way you will have to go. I was just going to post that I just now remembered you just put the php document's path in the img source :) I don't know why you would want to do it like you do but as you know it can't be done.

If your problem has been solved, please also mark the thread as solved :)

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.