Page 1 of 1

the image cannot be displayed because of errors

Posted: Mon Apr 07, 2008 10:02 pm
by seco
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hi
i try the following code to write a text on image and it gives me error says: "the image cannot be displayed because of errors"

Code: Select all

<?php
header("Content-type: image/png");
$im = imagecreatetruecolor(400, 30);
 
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
 
$text = 'www';
$font = 'arial.TTF';
 
imagettftext($im, 20, 0, 10, 20, $black, $font,$text);
imagepng($im);
?>

any idea where is the wrong?
im using wamp when i try other server it gives me the error at line 2 the header() line
any help?

thanks in advance.


~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: the image cannot be displayed because of errors

Posted: Tue Apr 08, 2008 2:44 am
by onion2k
It means there's a problem with the image so your browser can't display it. Comment out the header() and imagepng() lines so the script returns plain text and you'll see what that error is.

Re: the image cannot be displayed because of errors

Posted: Tue Apr 08, 2008 10:09 am
by seco
thanks for reply

the code in php.net that draws text on image gives me also the error: "cannot modify header information because is already sent by line 2"

Code: Select all

<?php
header("Content-type: image/png");
 
// Create the image
$im = imagecreatetruecolor(400, 30);
 
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
 
// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';
 
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
 
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
 
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
any idea how to make this code works?

thanks in advance.

Re: the image cannot be displayed because of errors

Posted: Wed Apr 09, 2008 2:44 am
by onion2k
the code in php.net that draws text on image gives me also the error: "cannot modify header information because is already sent by line 2"
That isn't a PHP error. Copy and paste exactly what the script outputs here.