View previous topic :: View next topic |
Author |
Message |
Mikor -
Joined: 21 Aug 2006 Posts: 144 Location: Hull, England
|
Posted: Wed Aug 23, 2006 6:01 pm Post subject: Whats wrong with this GD? |
|
|
I just get this:
Code: | The image “http://localhost:1024/home/images/online.php” cannot be displayed, because it contains errors. |
Here is my code:
Code: | <?php
header("Content-type: image/gif")or die("Could not send header.");
putenv('GDFONTPATH=' . realpath('.'))or die("Could not set environmental variable.");
$text = array();
$text[0] = 'Server Software: Abyss Web Server X1';
$text[1] = 'Server Uptime: ' . $_SERVER['X_ABYSS_STATS_SERVER_UPTIME'];
$text[2] = 'Server Output: ' . $_SERVER['X_ABYSS_STATS_SERVER_OUTPUT'] . ' bytes';
$image = array();
$image['font_size'] = 10;
$image['font_angle'] = 0;
$image['font_file'] = 'trebuchet_ms';
$image['text_x'] = 10;
$image['text_y'] = 10;
$image['text_colour'] = imagecolorallocate($im, 13, 28, 51)or die("Could not allocate text colour.");
$im = imagecreatefromgif("images/online.gif")or die("Could not initialize GD stream");
$y = $image['text_y'];
foreach($text as $line){
imagettftext($im, $image['font_size'], $image['font_angle'], $image['font_x'], $y, $image['text_colour'], $image['font_file'], $line)or die("Could not append text to image");
$y = $y + 15;
}
imagegif($im)or die("Could not send image.");
imagedestroy($im)or die("Could not destroy image");
?> |
_________________ Yarrt.com - Free Arcade
RypNet.co.uk - Online Game
MSN: michael_walker_2004 <at> hotmail <dot> com
Last edited by Mikor on Wed Aug 23, 2006 6:14 pm; edited 1 time in total |
|
Back to top |
|
|
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Wed Aug 23, 2006 6:12 pm Post subject: |
|
|
Quote: | <br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>h:\gd.php</b> on line <b>17</b><br />
<br />
<b>Warning</b>: imagettftext(): Could not find/open font in <b>h:\gd.php</b> on line <b>24</b><br />
<br />
<b>Warning</b>: imagettftext(): Could not find/open font in <b>h:\gd.php</b> on line <b>24</b><br />
<br />
<b>Warning</b>: imagettftext(): Could not find/open font in <b>h:\gd.php</b> on line <b>24</b><br />
|
_________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
|
Mikor -
Joined: 21 Aug 2006 Posts: 144 Location: Hull, England
|
Posted: Wed Aug 23, 2006 6:15 pm Post subject: |
|
|
hmm, php should be telling me that..
i'll look at my code again _________________ Yarrt.com - Free Arcade
RypNet.co.uk - Online Game
MSN: michael_walker_2004 <at> hotmail <dot> com |
|
Back to top |
|
|
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Wed Aug 23, 2006 6:16 pm Post subject: |
|
|
If you look at the source code of the page telling you it has errors its in there. It wont display it since FF thinks its an image not text. _________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
|
Mikor -
Joined: 21 Aug 2006 Posts: 144 Location: Hull, England
|
Posted: Wed Aug 23, 2006 6:16 pm Post subject: |
|
|
AbyssUnderground wrote: | If you look at the source code of the page telling you it has errors its in there. It wont display it since FF thinks its an image not text. |
ah, ok
edit: i've found the problem, its not sending the header, any ideas why?
edit2: its fixed now, and I dont know why, lol _________________ Yarrt.com - Free Arcade
RypNet.co.uk - Online Game
MSN: michael_walker_2004 <at> hotmail <dot> com |
|
Back to top |
|
|
pkSML -
Joined: 29 May 2006 Posts: 952 Location: Michigan, USA
|
Posted: Fri Aug 25, 2006 1:07 am Post subject: |
|
|
Glad you got it working. I see your sig.
There were a few problems that I debugged.
- First of all, the header syntax was incorrect. There can't be a die function attached to this line.
I solved it by just commenting out the die function and inserting a semicolon:
Code: | header("Content-type: image/gif"); // or die("Could not send header."); |
Secondly, this line Code: | $im = imagecreatefromgif("images/online.gif")or die("Could not initialize GD stream"); | must be before this line Code: | $image['text_colour'] = imagecolorallocate($im, 13, 28, 51)or die("Could not allocate text colour."); | The $im variable was not initialized yet, thus PHP threw this error: Quote: | Warning: imagecolorallocate(): supplied argument is not a valid Image resource in E:\Website\php\gdprob.php on line 17
Could not allocate text colour. |
One minor error... This line references an undefined variable: Quote: | imagettftext($im, $image['font_size'], $image['font_angle'], $image['font_x'], $y, $image['text_colour'], $image['font_file'], $line)or die("Could not append text to image"); | The underlined portion needs to be changed to text_x
Hope this sheds some light on your problem. _________________ Stephen
Need a LitlURL?
http://CodeBin.yi.org |
|
Back to top |
|
|
|