Click to See Complete Forum and Search --> : gd image generation failing on one site working on another both same host same setup


BWWebDesigns
03-09-2008, 03:58 PM
I am having some trouble with gd image creation

I have some code that works

$pic = "donationmeter/imagesadv/donation-meter0.png";
header("Content-type: image/png");
$im = imagecreatefrompng($pic); /* Attempt to open */
//$bg = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
$red = imagecolorallocate($im, 255, 0, 0);
$green = imagecolorallocate($im, 0, 205, 0);
$blue = imagecolorallocate($im, 0, 0, 255);
//$goal = number_format ($goal, 2);
$stringa = "Goal : ";
$stringb = $cursym.$goal;
if($new_value2<$goal) {
$redgreena = imagecolorallocate($im, 0, 205, 0);
} else {
$redgreena = imagecolorallocate($im, 255, 0, 0);
}
$string2a = "Donated : ";
$string2b = $cursym.$new_value2;
$red = imagecolorallocate($im, 255, 0, 0);
$string3a = "PayPal";
$string3b = "Fees";
$string3c = ":";
$string3d = $cursym.$fees;
$left = $goal-$total;
$left = number_format($left, 2);
//$left = number_format($left, 2);
if(eregi("-",$left)) {
$redgreenb = imagecolorallocate($im, 0, 205, 0);
} else {
$redgreenb = imagecolorallocate($im, 255, 0, 0);
}
$string4a = "Left : ";
$string4b = $cursym.$left;
$string5a = $res."%";
$string5b = " Of Our Goal";
if($res<100) {
$redgreenc = imagecolorallocate($im, 255, 0, 0);
} else {
$redgreenc = imagecolorallocate($im, 0, 205, 0);
}

if($res<3) {
$string6 = "Donations Needed!";
} elseif(($res<35) && ($res>=3)) {
$string6 = " Getting There!";
} elseif(($res<50) && ($res>=35)) {
$string6 = "Almost Half Way!";
} elseif(($res<70) && ($res>=50)) {
$string6 = "Half Way There!";
} elseif(($res<100) && ($res>=70)) {
$string6 = "Almost There Now!";
} elseif($res>=100) {
$string6 = "We Did It YAY!";
}

$px = (imagesx($im) - 21 * strlen($string5b)) / 2;
imagestring($im, 2, 13, 35, $stringa, $black);
imagestring($im, 2, 55, 35, $stringb, $green);
imagestring($im, 2, 13, 55, $string2a, $black);
imagestring($im, 2, 72, 55, $string2b, $redgreena);
imagestring($im, 2, 13, 75, $string3a, $black);
imagestring($im, 2, 13, 88, $string3b, $black);
imagestring($im, 2, 60, 78, $string3c, $black);
imagestring($im, 2, 72, 78, $string3d, $red);
imagestring($im, 2, 13, 108, $string4a, $black);
imagestring($im, 2, 54, 108, $string4b, $redgreenb);
imagestring($im, 2, $px, 128, $string5a, $redgreenc);
imagestring($im, 2, 44, 128, $string5b, $black);
imagestring($im, 2, 16, 148, $string6, $blue);
imagepng($im);
imagedestroy($im);

This successfully displays an image and puts a bit of text in it in places etc

However the script im creating has some more php code above this that includes a settings file and opens a database connection does some calculations based on the database contents etc

It successfully works on my own site but someone else who is using it is having problems and i cannot figure out why

If i use just the bit of code that generates the image it works fine, but if i have the include statement at the top i get the following error

Warning: Cannot modify header information - headers already sent by (output started at /home/content/etc/etc/etc/donationmeter/dbsettings.php:1) in /home/content/etc/etc/etc/test2.php on line 10
�PNG  IHDR�J,� IDATH���}t�u'x�{U���$�dD���)Hdggc���b'{b���CV<1��d�xvp���dg����� ���$���G����<����h�ݑ��2��lGTb���o��@wU�w��q� ݍ��n�M�~���_U�WU]���ݯ�"E�)R�H�"E�)R�H�i�[})�������Ǭ����zz�|��}��Ȓ1�Zk�����٩��W��꫾���� H��9�����A�����?��A���׫W?�@L<��ٳg3�����k���y�"EW����#�ȑ#G^}��W�q�/�pa�X2� �\1606b���l�#搸l�S�Tnܸq�������Go�m�i�)�^_���px?�o��7c�Mŕy�z��Õy��,��:z6�}��_��?�?�~� `�/h۶��l��4XǨ���"7�����u/--]�vm�?}�嗍1�z?w.:I��0��O����q�Mx�U���$^��/�������y�С��\.bnj�Y)�j/���1�w�}���>���|���)�3t:�~�Ax8ߑ�n'�x ���_��C|��~m�w��۷oϞ�3�R�}= �@6����ߧ@b0�"��)����^ �������_����5�� vC8���<� ؛����f8�O<w��+�P�¿��O=��c�����؞{��f3�X "�y�@�L�� ���������C"��R����sϾ��x�C��v��������|>?66���gff���Baxxx``୷�*�Jug <��3�{������fff*��k����Ї>4==���$�N}��O����Å�w�w���u 1e&\*�qiz�ÖB�//�W^�ظ�귞yꩧ����Ν;�ڝ�d�r%@T��#sM�C�5ᳪ�FU%QAD@D� S���������_�q[ɨ3g� NOO?����������ò]*� etc etc etc

The settings file just contains a few lines of $somevariable = "Some content";

Line 10 which it refers to in the error is the line starting header(

I have no idea why this script works on my site but not on this other persons site

I have checked evrything i can, both sites are hosted with godaddy on linux hosting with identical configurations from what i can tell

Can anyone shed any light on what is happening and why it is not working?

Thanks in advance

scragar
03-09-2008, 05:03 PM
apparantly you have some content in
/home/content/etc/etc/etc/donationmeter/dbsettings.php on line 1
output started at /home/content/etc/etc/etc/donationmeter/dbsettings.php:1

just do a quick check for new lines and/or spaces before you open PHP tags.

BWWebDesigns
03-09-2008, 05:14 PM
I checked my dbsettings.php file and this is what it contains

<?PHP
$dbhost = "";
$dbusername = "";
$dbpass = "";
$dbname = "";
$cursym = "$";
$dateformat = "jS M Y";
$zone=3600*-5;
$lastxdonations = "10";
$CompanyName = "";
$websiteURL = "";
$CompanyEmail = "";
$goal = "15000";
?>

With info filled in for the site and db settings

So i dont see any new lines or any errors that you mentioned

Plus this exact same script with no modification works on one site but ont on the other

Both sites are hsoted through the same company as previously mentioned

Thats what i didnt uderstand i knew what the error message meant but i couldnt see anything in the dbsettings.php file thta would cause that error, no echo statements, no newlines before or after the php tags or anything