473,404 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Drawing lines

I want to draw a line chart with PHP. If I make my Draw() function the only
function call, it works fine. But if I display other data, and then call my
Draw() function, I get a bunch of graphics characters, and some text. The
text says I have already defined the header info. Here is the ledgible part
of the text

Warning: Cannot modify header information - headers already sent by (output
started at /home/virtual/site8/fst/var/www/html/laps/laps.php:10) in
/home/virtual/site8/fst/var/www/html/laps/lib.php on line 498

Here is my Draw() function. I just cut and pasted some code off a website.
I can't even draw a single line yet!

<?php
function Draw()
{
Header("Content-type: image/jpeg");
$image = ImageCreate(200,150);
$gray = ImageColorAllocate($image,204,204,204);
$blue = ImageColorAllocate($image,0,0,255);
ImageLine($image,10,10,150,30,$blue);
ImageJPEG($image);
ImageDestroy($image);
}?>

Any ideas why I cannot call the Header function here, or why my web page
just shows a bunch of text and graphic characters ?

Thanks,
Doug
Jul 17 '05 #1
5 2336

"Douglas Hay" <xx*@xxx.com> wrote...
Any ideas why I cannot call the Header function here


Make sure your <?php statement is the very start of the file. Any white
space will count as HTML output. Any HTML output sends the headers.

--
Stephen Oakes
Jul 17 '05 #2
Douglas Hay wrote:
I want to draw a line chart with PHP. If I make my Draw() function the
only
function call, it works fine. But if I display other data, and then call
my
Draw() function, I get a bunch of graphics characters, and some text. The
text says I have already defined the header info. Here is the ledgible
part of the text


Hi,

2 things I can think of:
1) Did you echo anything?
Like echo "myvar = $myvar";
This can also be caused by whitespaces before the script starts.

2) Maybe you made some error, and PHP spits it out.
So you are generating text (errormessages).

Tip:
View the result of the image in a texteditor, and look for errorlines.

Good luck.

Regards,
Erwin Moller

Jul 17 '05 #3
Douglas Hay wrote:
I want to draw a line chart with PHP. If I make my Draw() function the only
function call, it works fine. But if I display other data, and then call my
Draw() function, I get a bunch of graphics characters, and some text. The
text says I have already defined the header info. Here is the ledgible part
of the text

Warning: Cannot modify header information - headers already sent by (output
started at /home/virtual/site8/fst/var/www/html/laps/laps.php:10) in
/home/virtual/site8/fst/var/www/html/laps/lib.php on line 498

Here is my Draw() function. I just cut and pasted some code off a website.
I can't even draw a single line yet!

<?php
function Draw()
{
Header("Content-type: image/jpeg");
$image = ImageCreate(200,150);
$gray = ImageColorAllocate($image,204,204,204);
$blue = ImageColorAllocate($image,0,0,255);
ImageLine($image,10,10,150,30,$blue);
ImageJPEG($image);
ImageDestroy($image);
}?>

Any ideas why I cannot call the Header function here, or why my web page
just shows a bunch of text and graphic characters ?

Thanks,
Doug

Doug,

That's correct. Headers must be sent BEFORE anything else is sent.

You're example will create a page with a single jpeg. You can't have
any other content on the page.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 17 '05 #4
Douglas Hay wrote:
I want to draw a line chart with PHP. If I make my Draw() function the only
function call, it works fine. But if I display other data, and then call my
Draw() function, I get a bunch of graphics characters, and some text. The
text says I have already defined the header info. Here is the ledgible part
of the text

Warning: Cannot modify header information - headers already sent by (output
started at /home/virtual/site8/fst/var/www/html/laps/laps.php:10) in
/home/virtual/site8/fst/var/www/html/laps/lib.php on line 498

Here is my Draw() function. I just cut and pasted some code off a website.
I can't even draw a single line yet!

<?php
function Draw()
{
Header("Content-type: image/jpeg");
$image = ImageCreate(200,150);
$gray = ImageColorAllocate($image,204,204,204);
$blue = ImageColorAllocate($image,0,0,255);
ImageLine($image,10,10,150,30,$blue);
ImageJPEG($image);
ImageDestroy($image);
}?>

Any ideas why I cannot call the Header function here, or why my web page
just shows a bunch of text and graphic characters ?

Thanks,
Doug

If you have used echoe/print etc.. then headers are already sent. To
get around this problem use two pages/php scripts. The first is the
display file containing your formatting page stuff. Somewhere in that
file you call the second script that creates the jpg, using <img
src="jpg-generating-php.php"> which is the script you alreay posted that
draws lines. This second script does set the headers, but they are
expected in the image tag.

Good luck.
Jul 17 '05 #5
Thanks for all the help, Craig's suggestion worked great and I got it
working now.

Thanks to all of you!

Doug

"Craig Storey" <cr*********@nrc.ca> wrote in message
news:d3**********@nrc-news.nrc.ca...
Douglas Hay wrote:
I want to draw a line chart with PHP. If I make my Draw() function the only function call, it works fine. But if I display other data, and then call my Draw() function, I get a bunch of graphics characters, and some text. The text says I have already defined the header info. Here is the ledgible part of the text

Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site8/fst/var/www/html/laps/laps.php:10) in
/home/virtual/site8/fst/var/www/html/laps/lib.php on line 498

Here is my Draw() function. I just cut and pasted some code off a website. I can't even draw a single line yet!

<?php
function Draw()
{
Header("Content-type: image/jpeg");
$image = ImageCreate(200,150);
$gray = ImageColorAllocate($image,204,204,204);
$blue = ImageColorAllocate($image,0,0,255);
ImageLine($image,10,10,150,30,$blue);
ImageJPEG($image);
ImageDestroy($image);
}?>

Any ideas why I cannot call the Header function here, or why my web page
just shows a bunch of text and graphic characters ?

Thanks,
Doug

If you have used echoe/print etc.. then headers are already sent. To
get around this problem use two pages/php scripts. The first is the
display file containing your formatting page stuff. Somewhere in that
file you call the second script that creates the jpg, using <img
src="jpg-generating-php.php"> which is the script you alreay posted that
draws lines. This second script does set the headers, but they are
expected in the image tag.

Good luck.

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: T. F. | last post by:
Hi, I need to create a box / field that the user can draw into (with some kind of pen). I also need to know how I can edit the size of the pen style and how I can "transport" the drawn image...
2
by: Champika Nirosh | last post by:
Hi, I want to create drawing board application that can draw Line, rectagle, circle and free hand drawing. Each drawing need to be transparent, moveable (draggable), have bring to front and...
0
by: borhan | last post by:
I am designing a program in which the user will be drawing, lines, circules and so on, on a paint control which displays an image opened by the user. "It's like there is a map on the picturebox...
8
by: Benoit Martin | last post by:
I had to draw my own control because I couldn't find any control doing what I wanted it to do. This control has a grid that I need to have control over. To do that, I draw each line of the grid...
2
by: George | last post by:
Dear colleagues, I refer to your help with specific graphic problem. It is necessary to create a viewfinder in graphic application. It seems that the algorithm is simple: just draw lines in...
9
by: davetelling | last post by:
I am not a programmer, I'm an engineer trying to make an interface to a product I'm designing. I have used C# to make a form that interrogates the unit via the serial port and receives the data. I...
4
by: Galen Somerville | last post by:
My VB2005 app gets real time Heart sounds and an ECG from a USB device. I'm looking for a way to speed up the drawing of the traces on the screen. In the following code the routine GetSounds...
4
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, I've windows form, in this form i've a panel. I want to draw lines inside the panel using the panel coordinates( meaing that the left upper corner of the panel is 0,0), how can i do it? ...
1
by: YouPoP | last post by:
I am doing an app (C# 2.0) where you can draw in a panel with your mouse in "real time". I actually have 2 problems; 1- it does not really is "real time", if your mouse move fast or very fast the...
5
by: Macias | last post by:
Hi, Please help me, how I can make a line drawing on PictureBox similar to MS paint. I thinking about this: click and hold button, move mouse and relase button. I'm trying useing this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.