-2

I've been looking into PHP GD an awful lot, but all the examples seem to indicate that you need to redirect the browser to another page. Now I've managed to get it displayed inline by writing a php file that runs the picture painting code. What I need to do now, is to stop all the random text appearing at the top of the screen. How do I do that?

christopher
  • 26,815
  • 5
  • 55
  • 89

2 Answers2

2

GD generates images. Images can be put in <img> tags. <img> is HTML. HTML is styled be CSS. Therefore CSS will allow you to place the image where you want.

Example:

<img src="my_gd_image.php" style="position: fixed; left: 20px; bottom: 40px;" />
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
  • Hi. I managed to get the image to appear, but this is the text at the top of my screen: �PNG IHDR}}�PLTE������]IDATX��W���0�|��+�"��G���8!�r!m�!q����X�T1�ap�L��|����!�sc�1��\؋1��Hǀ*/:R6��],��\�*l�Q D�ePt�=��c�+ɕ$��)�b�݃�b�lm�t�9�ṛx\�����y�֕�r�@�tO&�) ��� p%M5�,Q)�B���G6�ԤcT���+TYt HK���!˵�!��0V��w|�E�R�g��@l�Ă\jIո'�~�=��_<,^Q�!2p�e�pR�B�x�jd�C�x�dx^_���d I couldn't include all of it because the forum won't let me. It looks like an encoding, but how do I get rid of it? – christopher Dec 08 '12 at 16:30
  • 1
    That's your PNG file. You're viewing it in a text context, which doesn't make sense. Put it in an `` tag to create an image context. – Niet the Dark Absol Dec 08 '12 at 16:30
  • I am viewing it in an image context. It just seems to be outputting itself in a text context too.. rather strange! Have you heard of this before? – christopher Dec 08 '12 at 16:32
  • Have I heard of an `` tag showing its contents as plain text? No, I have not. Please show me. – Niet the Dark Absol Dec 08 '12 at 16:33
  • Echoing the raw image data won't work either, unless including it as a [Data URI](http://stackoverflow.com/questions/1207190/embedding-base64-images). You should just write a script for image generation only, and use it as the `src` attr of your `` tag. Anyway, *please show your code*! – moonwave99 Dec 08 '12 at 16:33
  • I've just realised the problem. Some testing code from before. I was setting the image to a variable, and that was outputting it as text. Not sure why it was being outputted, but the problem is fixed. +1 for helping me out! – christopher Dec 08 '12 at 16:34
  • 1
    @ChrisCooney Oh you just found a bug in stackoverflow of text overflowing – Mr. Alien Dec 08 '12 at 16:34
  • 1
    I noticed that! Good work team random bug finders. – christopher Dec 08 '12 at 16:37
0

PGP GD renders stuff to binary data, which may get stored in a file or returned as an HTTP response.

This has nothing to deal with browser itself: you just render an image via yourscriptname.php with proper HTTP headers, then you place it inside your html layout via markup and CSS:

<img src="yourscriptname.php?someParam=someValue" alt="Some alt text here.">
moonwave99
  • 21,957
  • 3
  • 43
  • 64