Dynamic display image along with text in same webpage

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nitint
Forum Newbie
Posts: 2
Joined: Fri Oct 17, 2008 5:42 am

Dynamic display image along with text in same webpage

Post by nitint »

Hi,

I am new to this form and also PHP, don't know if this is the right place to post my queries, but please help me with my problem if possible


Setup Details:
I have set up GD sitting on php, and having mysql as my database.
The whole thing is running on apache.

Issue
I would like to display some text along with a table (the data will come from mysql), and also a graph (pie chart or bar chart, using GD) in the same webpage.
Every user who logs in has different data and hence different graphs.

Right now i am creating a image file in server (jpeg/png doesn't really matter) and then displaying the image. The code is as shown below.

Imagejpeg($handle,"report.jpeg",100);
imagedestroy($handle);
echo "<img src='report.jpeg'><p></p>";
................................
?>

This above code creates a image file in the server and as there are many users i can not afford to create and store the image for all the users.

If i try to display image dynamically(without actullay creating a image file) i am seeing junk caracters. The issue may be related to content-type in a page.

Now, I would like to know if there is any way that i can display the image without actually creating a file in server.

Thanks in anticipation of your help.
Nitin
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Dynamic display image along with text in same webpage

Post by VladSun »

You could use two PHP files - one for generating the HTML, and one for generating the image. In the "HTML" PHP file you call the second one like this:

Code: Select all

<image src="image_generator.php?val1=value1&val2=value2">
In the "image" PHP file use:

Code: Select all

header('Content-type: image/jpeg');
before outputting the image content.
There are 10 types of people in this world, those who understand binary and those who don't
nitint
Forum Newbie
Posts: 2
Joined: Fri Oct 17, 2008 5:42 am

Re: Dynamic display image along with text in same webpage

Post by nitint »

Thanks for your help, This was the fastest help i received from various sites.
really appreciate
Post Reply