user1123513
user1123513

Reputation: 25

Generating an image - The image cannot be displayed because it contains errors

I'm using the code below to display an image that shows text of how many users are connected to my site. I replaced the image that I was using 'vad.png' with a different one. Now I'm getting the error "The image cannot be displayed because it contains errors"

Anyone know how I can fix this?

$result = mysql_query("SELECT * FROM server_status"); 

$row = mysql_fetch_array( $result ); 
$text = "Online"; 
$image = imagecreatefrompng('vad.png'); 
$black = imagecolorallocate($image, 10, 0, 0);
if (strlen($row['users_online']) >= 3){ 
imagefttext($image, 11, 0, 435, 38, $black, './verdana.ttf', $row['users_online']); 
}
else
{
imagefttext($image, 11, 0, 440, 38, $black, './verdana.ttf', $row['users_online']); 
}
imagefttext($image, 8, 0, 432, 55, $black, './verdana.ttf', $text); // Remove the // ahead of this line to use it 
header('Content-type: image/png'); 
imagepng($image); 
imagedestroy($image);

Upvotes: 0

Views: 4353

Answers (3)

pgarnek
pgarnek

Reputation: 1

I've found that when I've uploaded some files to web server, they won't display and mozilla show information about errors in file...

The problem was caused by transfer type in filezilla, it should be BINARY or AUTO, not ASCII. that was my solution for my problem, maybe it would be helpfull for someone

Upvotes: 0

EstebanSmits
EstebanSmits

Reputation: 91

I got this error once when I had accidentally transferred over some 0 byte image cache files from one server to another. You may want to check that out, it could be a invalid cache file or it can't overwrite it even.

Here is a blog post where I wrote about this. http://www.daxmax.com/index.php/2012/03/20/wordpresstimthumb-image-cannot-be-displayed-because-it-contained-errors/

Upvotes: 0

Cheery
Cheery

Reputation: 16214

Comment the header('Content-type: image/png'); and call the script from browser. Check for messages that might appear before the garbage related to the image itself.

You may need to add error_reporting(E_ALL); ini_set('display_errors', 1); at the top of the script in case error reporting/display is turned off as well.

Upvotes: 2

Related Questions