Current location: Hot Scripts Forums » Programming Languages » PHP » [Merged]GD Image Output Problem


[Merged]GD Image Output Problem

Reply
  #1 (permalink)  
Old 05-30-06, 02:26 PM
Ligx Ligx is offline
Newbie Coder
 
Join Date: Nov 2005
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
GD Image Output Problem

PHP Code:

include("config.php");


if (
$this_version == $real_version){
    
$up_to_date "Du har den siste versjonen! (".$real_version.")";}
else{
    
$up_to_date "Du har ikke den siste versjonen! (".$real_version.")";    
}

header ("Content-type: image/gif");
$img_handle ImageCreate (40018) or die ("Cannot Create Image");
$back_color ImageColorAllocate ($img_handle102102102);
$txt_color ImageColorAllocate ($img_handle255255255);
ImageString ($img_handle400,  $up_to_date$txt_color);
ImageGIF ($img_handle); 
Heres the problem; "Headers Already sent".
I need to output the image without this happening/ without using header information. like this somehow:

PHP Code:

$img_handle ImageCreate (40018) or die ("Cannot Create Image");

$back_color ImageColorAllocate ($img_handle102102102);
$txt_color ImageColorAllocate ($img_handle255255255);
ImageString ($img_handle400,  $up_to_date$txt_color);
ImageGIF ($img_handle); 
Help is really apriciated of course! =)
Reply With Quote
  #2 (permalink)  
Old 05-30-06, 03:45 PM
Rayden Rayden is offline
Newbie Coder
 
Join Date: May 2006
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
you have this code in a page where the header probably in config.php

I think the solution is to incude the codes in a different page.
Reply With Quote
  #3 (permalink)  
Old 05-30-06, 04:36 PM
Ligx Ligx is offline
Newbie Coder
 
Join Date: Nov 2005
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
and then require
PHP Code:

ImageGIF ($img_handle); 

?

Edit: Don't seem to make a difference except making a MySQL error "Out of Memory"

Last edited by Ligx; 05-30-06 at 04:40 PM.
Reply With Quote
  #4 (permalink)  
Old 05-30-06, 05:10 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
The "Headers Already sent" error occurs when output (including white space like a new line or a space) has already been sent to the browser and then you output something that uses a header. You can either find what is being output and eliminate it, or if you are deliberately outputting something, you can use output buffering to get around this problem - http://us3.php.net/manual/en/ref.outcontrol.php
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #5 (permalink)  
Old 05-31-06, 08:25 AM
Ligx Ligx is offline
Newbie Coder
 
Join Date: Nov 2005
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
GD Image Output Problem - Part Two

I have posted another thread, but I did'nt seem to understand/find the solution.
I am trying to ouput a GD generated image, but it don't seem to work without posting the header information;
PHP Code:

header ("Content-type: image/gif"); 

First time for me working with GD, so interested in some complete tutorials if someone has it. But for a start, I apriciate any help concerning this problem!

I am now posting the complete pages.

(Dont mind the norwegian errormessages)

startdoc.php
PHP Code:

<? $error $HTTP_GET_VARS["error"]; ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><? echo $sd_header?></title>
</head>
<body bgcolor="#333333" <? if ($error != ""){echo "onload=\"javascript:window.alert('$error');\"";} ?>>
browse.php (my main page)
PHP Code:

<? 

$csite 
"Browse Pages";
include(
"config.php");
include(
"docs/startdoc.php");
?>
<form id="browse" name="browse" method="post" action="action.php?a=browse">
  <table width="100%" border="1">
      <tr>
        <td colspan="2" bgcolor="#CCCCCC"><p align="center">&nbsp;
          </p>
          <p align="center">
              <select name="siteID" size="5" id="siteID">
              <option disabled="disabled">Velg Side</option>
              <? 
            $query 
"SELECT * FROM ".$prefix."sites ORDER BY 'id' DESC";  
            
$result mysql_query($query); 
            while(
$row mysql_fetch_array($result)){ ?>
              <option value="<? echo $row['id']; ?>"><? echo $row['description']; ?></option>
              <? ?>
                </select>
          </p>
          <p align="center">&nbsp;</p>
        </td>
      </tr>
      <tr>
        <td width="50%" bgcolor="#999999"><div align="left">
          <input name="logout" type="button" id="logout" value="Logg Ut" onclick="javascript:window.alert('For &aring; logge ut skikkelig m&aring; du lukke alle &aring;pne vinduer av nettleseren!')" />
        </div></td>
        <td width="50%" align="right" bgcolor="#999999"><select name="action">
          <option disabled="disabled">Velg Operasjon</option>
          <option disabled="disabled">------------</option>
          <option value="edit">Endre Side</option>
          <option value="view">Vis Side</option>
          <option value="add">Lag Ny Side</option>
          <option disabled="disabled">------------</option>
          <option value="position">Posisjonering</option>          
          <option disabled="disabled">------------</option>
          <option value="delete">Slett Side</option>
        </select>
          <input name="Submit" type="submit" id="Submit" value="Kj&oslash;r" /></td>
      </tr>
    </table>
</form>
<?
include("docs/enddoc.php");
?>
enddoc.php
PHP Code:

<br />

<br />
<table width="510" border="1" align="center">
  <tr>
    <td width="500" height="" nowrap="nowrap" bgcolor="#666666">
<?
include("version.php");
echo 
"".$sd_sys."<br />";
echo 
"".$sd_copyright.", for ".$sitename_clean."<br />";

if (
$sd_this_version == $sd_real_version){
    
$up_to_date "Du har den siste versjonen! (".$sd_real_version.")";}
else{
    
$up_to_date "Du har ikke den siste versjonen! (".$sd_real_version.")";    
}
    
header ("Content-type: image/gif");
$img_handle ImageCreate (40018) or die ("Cannot Create image");
$back_color ImageColorAllocate ($img_handle102102102);
$txt_color ImageColorAllocate ($img_handle255255255);
ImageString ($img_handle400,  $up_to_date$txt_color);
ImageGIF ($img_handle);

?>
    <br />
    <input type="button" name="changelog_pop" value="Changelog" onclick="changelog_pop('changelog.txt');" /></td>
  </tr>
  <tr>
    <td nowrap="nowrap" bgcolor="#666666"><a href="http://www.spreadfirefox.com/?q=affiliates&id=175412&t=57" target="_blank"><img src="http://www.swebxl.net/sdsys/public/images/firefox.gif" alt="Last Ned Firefox!" width="120" height="60" border="0" title="Last Ned Firefox!"/></a></td>
  </tr>
</table>
</body>
</html>

This GD script, I found from a tutorial.
When inserting the code at the wanted spot in the code, it outputs the error-message; Headers Already sent.
I can't seem to find were the headers are already sent.. It says
Code:
Warning: Cannot modify header information - headers already sent by (output started at /******/startdoc.php:6) in /******/enddoc.php on line 17
But where it says the output has already been sent, there's only an echo;
PHP Code:

<? echo $sd_header?>

which points to a var inside the config.php;
PHP Code:

/*###################################

# Versjon Nummer                    #
###################################*/
$sd_this_version "v2.0";


/*###################################
#####################################
# Ikke endre noe nedenfor           #
#####################################
###################################*/


/*###################################
# Diverse Unike Site Variabler      #
###################################*/
$sitename "Aloebiz.net - ";
$sitename_clean "Aloebiz.net";
$date_today date("d/m/y H:i:s");


/*###################################
# Versjon-Nummer av systemet        #
###################################*/
$sd_sys "SdSYS Control Panel";
$sd_header "$sd_sys - $sd_this_version :: $csite ($sitename_clean)";
$sd_header_clean "$sdsys - $version"
I may have posted too much here, boring to read, but any help is of course apriciated!

Could it be that the var is called $sd_header ?

Last edited by Ligx; 05-31-06 at 08:31 AM.
Reply With Quote
  #6 (permalink)  
Old 06-01-06, 02:51 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
you better store the image you want to create in another file. you have to specify the header when creating an image, and there may be no data displayed before you specify the header. so this is wrong (example):
PHP Code:

echo "hello";

header("Content-type: image/gif");
// create the image 
you just need to copy-past the code for the image into another page, and include that one. it should work then

Greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #7 (permalink)  
Old 06-02-06, 01:26 AM
Ligx Ligx is offline
Newbie Coder
 
Join Date: Nov 2005
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
This does not seem to work..
But thanks for the tip!!
Reply With Quote
  #8 (permalink)  
Old 06-06-06, 04:42 AM
Ligx Ligx is offline
Newbie Coder
 
Join Date: Nov 2005
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Anyone else has any solutions?
Reply With Quote
  #9 (permalink)  
Old 06-06-06, 06:35 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
Quote:
Originally Posted by Ligx
This does not seem to work..
But thanks for the tip!!
is it still the same error?

can you place a link to your website, so we can check ourselves?
did you change anything to code?

Greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #10 (permalink)  
Old 06-06-06, 06:42 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
I think I've got it. Here is what this needs. Place the following code into it's own .php file and remove it from where it is in the code now -
PHP Code:

<? 

include("version.php"); 
echo 
"".$sd_sys."<br />"
echo 
"".$sd_copyright.", for ".$sitename_clean."<br />"

if (
$sd_this_version == $sd_real_version){ 
    
$up_to_date "Du har den siste versjonen! (".$sd_real_version.")";} 
else{ 
    
$up_to_date "Du har ikke den siste versjonen! (".$sd_real_version.")";     

     
header ("Content-type: image/gif"); 
$img_handle ImageCreate (40018) or die ("Cannot Create image"); 
$back_color ImageColorAllocate ($img_handle102102102); 
$txt_color ImageColorAllocate ($img_handle255255255); 
ImageString ($img_handle400,  $up_to_date$txt_color); 
ImageGIF ($img_handle); 

?>
Where the above code was, put the following in as HTML (not as PHP) -
Code:
<img src="filename.php">
(where filename is what ever name you gave the first piece of code.)
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML table = Background Image versus Image problem Mickoes HTML/XHTML/XML 2 02-27-06 01:43 PM
Output A Text Page As Image, Via PHP... w2n Script Requests 11 01-05-06 11:53 AM
image problem jonnekke PHP 1 11-25-05 03:55 AM
Image manipulation color problem in ASP.NET munesh ASP.NET 0 01-07-05 05:35 AM


All times are GMT -5. The time now is 07:16 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.