[SOLVED]Question about "ImagePng"

GD and GD2 are useful libraries for creating graphics on-the-fly. Discuss your PHP GD and GD2 scripts here.

Moderators: onion2k, General Moderators

Post Reply
dreamline
Forum Contributor
Posts: 158
Joined: Fri May 28, 2004 2:37 am

[SOLVED]Question about "ImagePng"

Post by dreamline »

Hi All,
I've got a little question about ImagePng. I've read a lot of threads and I've been storing a Png image in a variable with ob_start();. It's a bit hard to explain what I want to do, but I'll give it a try. Because I am using this GD function dynamically I want to print out the contents of the variable to screen inside a <DIV> tag, however it needs to represent itself as an image. How would I print the contents of my variable (which holds the full GD PNG image) into a html page without first saving it to a file? Can I use header types inside my DIVS?

Thanks for any help... :)
Last edited by dreamline on Mon Jul 27, 2009 6:57 am, edited 1 time in total.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Question about "ImagePng"

Post by jackpf »

You have to link to a seperate file.

You could do it in one file like this though:

Code: Select all

 
if(!isset($_GET['blah']))
echo '<img src="'.htmlentities($_SERVER['PHP_SELF']).'?blah=1" />';
else
{
//do all your image stuff
}
 
dreamline
Forum Contributor
Posts: 158
Joined: Fri May 28, 2004 2:37 am

Re: Question about "ImagePng"

Post by dreamline »

Hi,
Thanks jackpf, it was not the answer I was hoping for because I don't want to write to file and want to output directly in my html page. I guess I will need to create all my text images by hand instead of creating them through imagePNG and then printing it in a html tag.

Thanks for your answer. :)
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Question about "ImagePng"

Post by jackpf »

I think you misunderstood...you don't have to write anything to a file.

Obviously to link to an image, you have to use an <img> tag. But you need a file to display the image as well.

By doing as I suggested, one file can act as both the picture, and the script that displays it.

Is that not what you wanted?
dreamline
Forum Contributor
Posts: 158
Joined: Fri May 28, 2004 2:37 am

Re: Question about "ImagePng"

Post by dreamline »

Yes, that's exactly what I want. I guess I did misonderstood. So I'll give it a go to see if I can manage to print to a <img> tag.. :)

Thanks and sorry I misunderstood.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Question about "ImagePng"

Post by jackpf »

Lol no problem. Good luck.
Post Reply