This is a discussion on php, GD library, Content-type within the PHP Language forums, part of the PHP Programming Forums category; Hello, I've managed to get as far as using some of the GD2 drawing functions included in the php_gd2....
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hello,
I've managed to get as far as using some of the GD2 drawing functions included in the php_gd2.dll. I can't figure out how to put HTML and PHP output on the same browser page, no doubt this has something to do with the header; any help would be greatly appreciated. Thank you, Gerard <?php header ("Content-type: image/png"); $t = imagecreate(400,150); // create a blank canvas $c = imagecolorallocate($t,0,255,0); // set color for the first thing imagefilledrectangle($t,10,10,50,50,$c); // draw a rectange $c = imagecolorallocate($t,215,20,20); // set color for the next imagefilledellipse($t,50,50,75,75,$c); // draw an ellipse $w = "it's not easy to learn this stuff!"; $c = imagecolorallocate($t,50,50,150); imagestring($t,4,100,70,$w,$c); imagepng($t); // output the image imagedestroy($t); // clear memory, but not the browser /* NOTHING FOLLOWING OUTPUTS */ echo "<pre>"; var_dump(gd_info()); echo "</pre>"; ?> |
|
|||
|
gerrymcc@indigo.ie wrote:
> Hello, > I've managed to get as far as using some of the GD2 drawing functions > included in the php_gd2.dll. I can't figure out how to put HTML and > PHP output on the same browser page, no doubt this has something to > do with the header; any help would be greatly appreciated. > Thank you, > Gerard > > <?php > header ("Content-type: image/png"); > > $t = imagecreate(400,150); // create a blank canvas > $c = imagecolorallocate($t,0,255,0); // set color for the first > thing > imagefilledrectangle($t,10,10,50,50,$c); // draw a rectange > $c = imagecolorallocate($t,215,20,20); // set color for the next > imagefilledellipse($t,50,50,75,75,$c); // draw an ellipse > $w = "it's not easy to learn this stuff!"; > $c = imagecolorallocate($t,50,50,150); > imagestring($t,4,100,70,$w,$c); > imagepng($t); // output the image > imagedestroy($t); // clear memory, but not the browser > > /* NOTHING FOLLOWING OUTPUTS */ > > echo "<pre>"; > var_dump(gd_info()); > echo "</pre>"; > > ?> > > > You can't. If it's an image, it isn't html - and vice versa. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
First save the image, then call it, or call this script thruoogh another
(wich contains the html/php) On 06-08-2007 14:56, in article yREti.21321$j7.381704@news.indigo.ie, "gerrymcc@indigo.ie" <gerrymcc@indigo.ie> wrote: > Hello, > I've managed to get as far as using some of the GD2 drawing functions > included in the php_gd2.dll. I can't figure out how to put HTML and > PHP output on the same browser page, no doubt this has something to > do with the header; any help would be greatly appreciated. > Thank you, > Gerard > > <?php > header ("Content-type: image/png"); > > $t = imagecreate(400,150); // create a blank canvas > $c = imagecolorallocate($t,0,255,0); // set color for the first > thing > imagefilledrectangle($t,10,10,50,50,$c); // draw a rectange > $c = imagecolorallocate($t,215,20,20); // set color for the next > imagefilledellipse($t,50,50,75,75,$c); // draw an ellipse > $w = "it's not easy to learn this stuff!"; > $c = imagecolorallocate($t,50,50,150); > imagestring($t,4,100,70,$w,$c); > imagepng($t); // output the image > imagedestroy($t); // clear memory, but not the browser > > /* NOTHING FOLLOWING OUTPUTS */ > > echo "<pre>"; > var_dump(gd_info()); > echo "</pre>"; > > ?> > > > |
|
|||
|
On 06.08.2007 14:56 gerrymcc@indigo.ie wrote:
> Hello, > I've managed to get as far as using some of the GD2 drawing functions > included in the php_gd2.dll. I can't figure out how to put HTML and > PHP output on the same browser page, no doubt this has something to > do with the header; any help would be greatly appreciated. > Thank you, > Gerard > hi there just a few lines: > <?php if(key($_GET) == 'img') { > header ("Content-type: image/png"); > > $t = imagecreate(400,150); // create a blank canvas > $c = imagecolorallocate($t,0,255,0); // set color for the first > thing > imagefilledrectangle($t,10,10,50,50,$c); // draw a rectange > $c = imagecolorallocate($t,215,20,20); // set color for the next > imagefilledellipse($t,50,50,75,75,$c); // draw an ellipse > $w = "it's not easy to learn this stuff!"; > $c = imagecolorallocate($t,50,50,150); > imagestring($t,4,100,70,$w,$c); > imagepng($t); // output the image > imagedestroy($t); // clear memory, but not the browser > die(); } > /* NOTHING FOLLOWING OUTPUTS */ > > echo "<pre>"; > var_dump(gd_info()); > echo "</pre>"; > echo "<img src={$_SERVER['PHP_SELF']}?img>"; > ?> hope this helps. PS Looks like you need a better understanding on how http and browsers work, do some reading on this. -- gosha bine makrell ~ http://www.tagarga.com/blok/makrell php done right ;) http://code.google.com/p/pihipi |
|
|||
|
gosha bine <stereofrog@gmail.com> wrote:
>hi there >just a few lines: >> <?php >if(key($_GET) == 'img') { >> header ("Content-type: image/png"); >> >> $t = imagecreate(400,150); // create a blank canvas >> $c = imagecolorallocate($t,0,255,0); // set color for the first >> thing >> imagefilledrectangle($t,10,10,50,50,$c); // draw a rectange >> $c = imagecolorallocate($t,215,20,20); // set color for the next >> imagefilledellipse($t,50,50,75,75,$c); // draw an ellipse >> $w = "it's not easy to learn this stuff!"; >> $c = imagecolorallocate($t,50,50,150); >> imagestring($t,4,100,70,$w,$c); >> imagepng($t); // output the image >> imagedestroy($t); // clear memory, but not the browser >> >die(); } >> /* NOTHING FOLLOWING OUTPUTS */ >> >> echo "<pre>"; >> var_dump(gd_info()); >> echo "</pre>"; >> >echo "<img src={$_SERVER['PHP_SELF']}?img>"; >> ?> >hope this helps. >PS Looks like you need a better understanding on how http and browsers >work, do some reading on this. Thanks very much, that works beautifully; I have only a vague idea why, so I hope you don't mind a question or two about it. 1) I presume that <img src=etc> sends a GET request to the server, something like thisFile.php?keyName. The server then looks at the file again, sees an 'img' key in $_GET and processes the script? 2) I know key() returns the key currently pointed to in the $_GET array, but there's no way I can see the content of that array, is there? I did a var_dump($_GET) but that shows an empty array. As you said, I have a LOT of reading to do :-) I spent a few hours last night searching; a Google on "http and web browsers" got many hits on specific browsers and the RFC on HTTP, but little of the information was useful in the context of understanding scripts like the above. If you could suggest any resources, that would be much appreciated too. Thanks again, Gerard |
|
|||
|
On 07.08.2007 12:05 gerrymcc@indigo.ie wrote:
> Thanks very much, that works beautifully; I have only a vague idea > why, so I hope you don't mind a question or two about it. That's what we are here for. ;) > 1) I presume that <img src=etc> sends a GET request to the server, > something like thisFile.php?keyName. The server then looks at the > file again, sees an 'img' key in $_GET and processes the script? Correct, you got it: acquiring html file and image are two distinct and absolutely independent requests in http. > 2) I know key() returns the key currently pointed to in the $_GET > array, but there's no way I can see the content of that array, is > there? I did a var_dump($_GET) but that shows an empty array. When you script is called with a single parameter name, without a value, the $_GET array looks like: array('param_name' => '') <-- empty string > As you said, I have a LOT of reading to do :-) I spent a few > hours last night searching; a Google on "http and web browsers" > got many hits on specific browsers and the RFC on HTTP, but little > of the information was useful in the context of understanding scripts > like the above. If you could suggest any resources, that would be > much appreciated too. I'd start here http://en.wikipedia.org/wiki/HTTP Also, "http sniffer" tools (that show the traffic from and to your browser) are very useful to understand what's going on. FireBug (firefox extension) includes such a tool. -- gosha bine makrell ~ http://www.tagarga.com/blok/makrell php done right ;) http://code.google.com/p/pihipi |