0
<?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ãÆ
richsage
  • 26,912
  • 8
  • 58
  • 65
goblin2986
  • 971
  • 3
  • 16
  • 32

3 Answers3

3

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);
?>
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • 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; } ?> – goblin2986 May 05 '10 at 13:38
  • this is my wordwrap function. – goblin2986 May 05 '10 at 13:39
  • @bhaskaragr I can't see a line 33 here. But just don't use it at all. use the code I added – Your Common Sense May 05 '10 at 13:43
  • thnaks i got it...i include the file in main....thanks a lot. – goblin2986 May 05 '10 at 13:49
2

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
  • 5,849
  • 4
  • 31
  • 57
0

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();
osm
  • 4,186
  • 3
  • 23
  • 24
  • 1
    That's massive over-kill which only works around the problem. It would be far better to *fix* the problem instead. – user229044 May 05 '10 at 12:21
  • 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 May 05 '10 at 13:36
  • After a weird behavoring of my system, I can't find any blank space, nothing and in no way it was redirecting, then my workaround was something like this -> echo ''; It really works! Is not the best solution, but after a lot of hassle 'cause a simple redirect is not working I came up with this.. – devasia2112 Oct 26 '11 at 16:09