tags:

views:

180

answers:

4
<?php 

require_once 'wordwrap.php';
$text="Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum";
$im=imagecreatefrompng('testing.png');
$arr=word($text);
$white = imagecolorallocate($im,255,255,255);
$grey = imagecolorallocate($im, 128, 128, 128);
$font='arial.ttf';
$m=121;
for($i=0;$i<sizeof($arr);$i++)
{

    //imagettftext($im,12,0,11,$m+$t,$grey,$font,$arr[$i]);
//echo $arr[$i]."<br/>";

}
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>

I am getting error.

Warning: Cannot modify header information - headers already sent by (output started at /home2/puneetbh/public_html/prideapp/Testing/wordwrap.php:33) in /home2/puneetbh/public_html/prideapp/Testing/checkimage.php on line 16
‰PNG  ��� IHDR�� ��ô���J"Þ/�� �IDATxœì¼KvÉŽ%ŠŸ}Ü)EfäjÕxÝËÇ›nE^)Èãn?�Õ€J‘UÕ~ß --ŠKä>ƒÛàÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ
A: 

turn on output buffering for changing header -> http://php.net/manual/en/function.ob-start.php

write this to top of your code.

ob_start();
Osman Üngür
That's massive over-kill which only works around the problem. It would be far better to *fix* the problem instead.
meagar
Upvoted, output buffering is a fine technique for certain issues, and highlighting it exists is perfectly reasonable, especially if a developer hasn't come across it before.
danp
+2  A: 

Make sure there are no spaces or returns before <?php. Also if your file is encoded as UTF-8 make sure it's without BOM

Manos Dilaverakis
no i am running in ANSI encoding.
bhaskaragr29
A: 

Manos could be right. If you're not sure about the BOM thing, open up a new Notepad window, copy-paste you code, save the file with ANSI encoding.

Edit ----

I am assumimg that you code does not generate any errors before the header code. If this is the case then you have to deal with that error first.

Salman A
+3  A: 

your wordwrap.php file should not output a byte. But it prints something out in the 33th line. You can check this line and see what happened.

Also consider to use bulit-in PHP function wordwrap() instead of including some strange code.

So, make it like this:

<?php 

#require_once 'wordwrap.php';
$text="Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum";
$im=imagecreatefrompng('testing.png');
$arr=explode("\n",wordwrap($text,24,"\n"));
$white = imagecolorallocate($im,255,255,255);
$grey = imagecolorallocate($im, 128, 128, 128);
$font='arial.ttf';
$m=121;
for($i=0;$i<sizeof($arr);$i++)
{

    //imagettftext($im,12,0,11,$m+$t,$grey,$font,$arr[$i]);
//echo $arr[$i]."<br/>";

}
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
Col. Shrapnel
<?phpfunction word($string){$spaceleft=24;$pieces = explode(" ", $string);for($i=0;$i<sizeof($pieces);$i++){ if(strlen($pieces[$i])>24) { $str=substr($pieces[$i],0,24); $text=$text.$str.":".substr($pieces[$i],24,strlen(str)); } else { if(strlen($pieces[$i])>$spaceleft) { $spaceleft=24; $text=$text.":".$pieces[$i]; } else { $spaceleft=$spaceleft-(strlen($pieces[$i])+1); $text=$text.$pieces[$i]." "; } } }$p=explode(":",$text);return $p;}?>
bhaskaragr29
this is my wordwrap function.
bhaskaragr29
@bhaskaragr I can't see a line 33 here. But just don't use it at all. use the code I added
Col. Shrapnel
thnaks i got it...i include the file in main....thanks a lot.
bhaskaragr29