Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GD image cannot be displayed, because it contains errors.

Status
Not open for further replies.

connectionscentres

Programmer
Jan 5, 2005
16
GB
Hi,

I am running php version 5.0.3 and I think I have GD enabled. On the php info page for my server it says:

GD Support enabled
GD Version bundled (2.0.28 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.1.7
T1Lib Support enabled
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XBM Support enabled

However, when I try and run any GD-related functions e.g. imagecreatefromjpeg($myimage); it fails and the browser shows.
The image “ cannot be displayed, because it contains errors.

I have made sure there are no unnecessary blank spaces and there are no syntax errors.

I have checked my apache log files and it complains that the supplied argument is not a valid Image resource.

I have therefore cut the code down to the bare minimum to just display a simple image
<?php
header ("Content-type: image/png");
$im = imagecreate (300, 300);
$white = imagecolorallocate ($im,255,255,255);
?>

Now I get no error codes in the apache log but it still doesnt display and says the same as before.

Any suggestions?

Cheers.
 
The code you have posted will not display an image. It will create an image in your server's memory, but it will not format that image as a PNG nor will it send that image to the user's browser. You need to invoke imagepng() to perform the crucial last two steps.

Take a look at the sample code on the PHP online manual page for imagecreate(). That shows a complete example for creating an image on the fly and sending it to the browser. That example code is even sending the image to the browser as a PNG.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top