I think what you're trying to do is the following. You will need at least two PHP scripts. One for the HTML (we'll call it A.PHP), one for the embedded GIF (B.PHP).
A.PHP does the following-
embed html and php here
<img src="/b.php">
B.PHP does the following-
Header("Content-type: image/gif")
...generate image here...
===========================================
http://badblue.com
Small footprint P2P web server for Windows,
File-sharing, PHP, wireless apps & more