the image cannot be displayed because of errors

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
seco
Forum Newbie
Posts: 23
Joined: Tue Jan 08, 2008 10:40 pm

the image cannot be displayed because of errors

Post 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.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: the image cannot be displayed because of errors

Post 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.
seco
Forum Newbie
Posts: 23
Joined: Tue Jan 08, 2008 10:40 pm

Re: the image cannot be displayed because of errors

Post 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.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: the image cannot be displayed because of errors

Post 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.
Post Reply