GD Support- "cannot be displayed, because it contains error"

GD and GD2 are useful libraries for creating graphics on-the-fly. Discuss your PHP GD and GD2 scripts here.

Moderators: onion2k, General Moderators

Post Reply
gauravgarden
Forum Newbie
Posts: 5
Joined: Tue Jul 08, 2008 4:26 pm

GD Support- "cannot be displayed, because it contains error"

Post by gauravgarden »

I have installed PHP 5.2.6 on Tomcat 5.5, OS - XP Pro.
phpinfo() shows gd support enabled.
But when I run basic script to verify that it is creating an image, it does not showing image. Is there any specific configuration for tomcat servlet?
the script is
<?php
$im = @ ImageCreate ( 150, 100)
or die ( "Cannot create a new GD image.");
$background_color = ImageColorAllocate ($im, 255, 255, 255);
$text_color = ImageColorAllocate ($im, 233, 14, 91);
ImageString ($im, 1, 5, 5, "A Simple Text String", $text_color );
header ("Content-type: image/png");
ImagePng ($im);
?>

Observations-
1. For IE it shows blank image box
2. for firefox it gives text message - The image “http://testbox:8080/phptest/1.php” cannot be displayed, because it contains errors."
3. When I run phpinfo(), in IE it shows blank php logo images and in firefox it does not display image.

Appriciate your valued help on this problem.
Attachments
GD Support enabled SS
GD Support enabled SS
SC.png (9.18 KiB) Viewed 22456 times
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: GD Support- "cannot be displayed, because it contains error"

Post by Benjamin »

Have you verified that the code works on other servers, but not yours?
gauravgarden
Forum Newbie
Posts: 5
Joined: Tue Jul 08, 2008 4:26 pm

Re: GD Support- "cannot be displayed, because it contains error"

Post by gauravgarden »

Yes, I did same setting on windows 2003 server and facing same issue.

I ran to see which extension are loaded with the script--
<?php
$cli = (php_sapi_name() == 'cli');
$eol = "\n";
$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{$le .= ' ' . implode(' ', array_slice($gle, $i, $wide)) . $eol;}
if (!$cli)
{ echo '<html><head><title>quick info</title></head><body><pre>', $eol; }
echo 'Loaded Extensions:', $eol, $le, $eol;
if (!$cli)
{ echo '</pre></body></html>', $eol; }
?>


-----Output ------
Loaded Extensions:
bcmath calendar com_dotnet ctype
session filter ftp hash
iconv json odbc pcre
Reflection date libxml standard
tokenizer zlib SimpleXML dom
SPL wddx xml xmlreader
xmlwriter java bz2 curl
gd
----------------------

It shows gd has been loaded.

Thanks
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: GD Support- "cannot be displayed, because it contains error"

Post by onion2k »

Works for me. Try commenting out the last two lines (header() and imagepng() ) and running it... you should see what the error is then.
gauravgarden
Forum Newbie
Posts: 5
Joined: Tue Jul 08, 2008 4:26 pm

Re: GD Support- "cannot be displayed, because it contains error"

Post by gauravgarden »

if I commented below two lines -
header ("Content-type: image/png");
ImagePng ($im);

Browser shows blank page without any error.

If I comment
header ("Content-type: image/png");

Firefox browser shows ascii charactes like -
‰PNG IHDR^•PLTEÿÿÿé[‘IDATxœc` ÀÌðˆ‡NA?&ÆÒÄ 1¶ì–Ž“O%?bì ‡Â\6p¦)ð¸u®„©kP o9À?Á©×{?¯€ëDŽIEND®B

and IE shows blank.

So I think image being created but not able to get in the browser from tomcat..

Thanks,
Amar
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: GD Support- "cannot be displayed, because it contains error"

Post by jayshields »

I had this exact error yesterday. I solved it in < 1 minute.

I went to the documentation, searched for "contains error" and got this:
http://www.aditus.nu/jpgraph/jpgraphfaq.php#F4.12

Which simply says turn off output buffering (ie. set it to 0).
gauravgarden
Forum Newbie
Posts: 5
Joined: Tue Jul 08, 2008 4:26 pm

Re: GD Support- "cannot be displayed, because it contains error"

Post by gauravgarden »

I verified the same article 3-4 days back. I verified my php.ini files at
C:\PHP\php.ini and c:\windows\php.ini

both have
output_buffering = Off

is there any other place where I need to do the above setting?

Thanks,
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: GD Support- "cannot be displayed, because it contains error"

Post by jayshields »

You should only have ONE php.ini.

Work out which one is actually being used by running phpinfo(); and then checking the Configuration File (php.ini) Path variable.

I guess Off is the same as 0, but try both.

Also take note of what is said in the read of that FAQ answer.
gauravgarden
Forum Newbie
Posts: 5
Joined: Tue Jul 08, 2008 4:26 pm

Re: GD Support- "cannot be displayed, because it contains error"

Post by gauravgarden »

tomcat is using c:\windows\php.ini.
I have verified all errors off and restarted tomcat. But still error persist.
;error_reporting = E_ALL & ~E_NOTICE
display_errors = Off
display_startup_errors = Off

rest all error are set to = Off.
Even I tried with 0, but no luck.

I tried to load a simple image from the browser http://testbox:8080/phptest/TS.gif but tomcat gives me error even though it exist in \webapps\phptest .

HTTP Status 404 - /phptest/TS.gif
type Status report
message /phptest/TS.gif
description The requested resource (/phptest/TS.gif) is not available.
Apache Tomcat/5.5.26

But at the same time if I browse images which are loaded while tomcat installation it works well.
Post Reply