Here is few thing you need to understand about PHP and HTTP protocol.
According to HTTP protocol header must have to be sent by the server first.
php treats its header and data in two ways:
1. php gether all data and header seperately and store it memory. After the end of execution php will send the header and then data
2. PHP will start to send data right away from the beginning of the execution.
In most case the servers are configured as no 2.
So, what you did here is first you put html code. then in the middle you are sending header. Before php send the first byte out it sends out all its header. That is, before php sends out "" php already send out the header. So, no matter how many header you set afterward they will not be effected. Now your case what is happening is even worse. First you are sending out some html text and then telling the parser that its an image. Even if you do the right thing i.e. first sending the header and then sending out data, it will still suffer. The reason is, you are still sending invalid data, your html texts, for your image. The right code would be
<?php
$myImage = imagecreate( 200, 100 );
$myGray = imagecolorallocate( $myImage, 204, 204, 204 );
$myBlack = imagecolorallocate( $myImage, 0, 0, 0 );
imageline( $myImage, 15, 35, 120, 60, $myBlack );
header( "Content-type: image/png" );
imagepng( $myImage );
imagedestroy( $myImage );
That is it. Make sure there is no other data before <?php and no data after ?>. it would be way better if you do not use ?>