 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
01-26-2008, 07:53 PM
|
#1 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
|
GD library... Oh god the errors...
PHP Code:
<html>
<head>
<title>Using the GD Library</title>
</head>
<body bgcolor="Gray">
<?php
$im = imagecreate(110, 20);
$white = imagecolorallocate($im, 255, 255, 255);
$string = imagestring($im, 1, 5, 5, "Hello world", $white);
header("Content-type: image/png");
imagejpeg($im, $sring);
imagedestroy($im);
?>
</body>
</html>
Good luck helping me debug this :/
It creates an image with the following error:
Parse error: parse error, unexpected T_STRING in C:\wamp\www\Lessons\GD\GD, The basics.php on line 9
Line 9 is the one with hello world, hello world is the string.
|
|
|
01-26-2008, 07:59 PM
|
#2 (permalink)
|
|
The Frequenter
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
|
I seriously do not know a lot of GD Libary. I know from experience that Dale is the meistro when it comes down to GD. (Rendair is his nick on the forum)
Simply debuggin this as I go so bare with me.
Ehm lol, on second notice, when you engage a header(), you can never and I mean NEVER have a output before the header(). I believe this is what you got from php.net;
PHP Code:
<?php // create a 100*30 image $im = imagecreate(100, 30);
// white background and blue text $bg = imagecolorallocate($im, 255, 255, 255); $textcolor = imagecolorallocate($im, 0, 0, 255);
// write the string at the top left imagestring($im, 5, 0, 0, "Hello world!", $textcolor);
// output the image header("Content-type: image/png"); imagepng($im); ?>
The one up here is perfect, and it should work.
:: edit ::
Oh yeah, instead of
$sring I should try $string. 
PHP Code:
imagejpeg($im, $sring);
=>
PHP Code:
imagejpeg($im, $string);
__________________
"Life is a bitch, take that bitch on a ride"
|
|
|
|
The Following User Says Thank You to ReSpawN For This Useful Post:
|
|
01-26-2008, 08:46 PM
|
#3 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
|
I saved over my old version before I saw your edit, I will check that out later. Right now I am having another issue, and I don't understand waht it could be.
PHP Code:
<?php $src_image = "logo.gif"; $image = imagecreatefromgif($src_image); $textcolor = imagecolorallocate($image, 255, 0, 0); $string = imagestring($image, 5, 0, 0, "Hello world!", $textcolor); header("Content-type: image/gif"); imagegif ($image, $string); ?>
It just displays a URL, and everything works fine if I get rid of $string in the code, but with it, it displays a URL.
Why is it that line 5 will change the image even when it is stored in a variable? Do certain functions in PHP do something when they are stored?
|
|
|
01-26-2008, 09:21 PM
|
#4 (permalink)
|
|
The Acquainted
Join Date: Nov 2007
Location: Netherlands
Posts: 113
Thanks: 11
|
If you're using firefox it can be displaying an url because there's something wrong with the image.. Try commenting out the header part to check for php errors..
|
|
|
|
01-26-2008, 09:51 PM
|
#5 (permalink)
|
|
The Frequenter
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
|
Quote:
Originally Posted by sjaq
If you're using firefox it can be displaying an url because there's something wrong with the image.. Try commenting out the header part to check for php errors..
|
Preferably using error_reporting ( E_ALL ^ E_NOTICE );
__________________
"Life is a bitch, take that bitch on a ride"
|
|
|
01-26-2008, 10:12 PM
|
#6 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
You don't need $string in there. There is no need to capture the return value from imagestring into a variable, and certainly no need to use that variable as the filename argument when calling imagegif.
|
|
|
|
01-26-2008, 10:17 PM
|
#7 (permalink)
|
|
The Frequenter
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
|
You can also check out "The Big GD Guide - Part 1" in Salathe sig. 
__________________
"Life is a bitch, take that bitch on a ride"
|
|
|
01-26-2008, 11:08 PM
|
#8 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by ReSpawN
You can also check out "The Big GD Guide - Part 1" in Salathe sig. 
|
Which also uses GD!
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
01-26-2008, 11:08 PM
|
#9 (permalink)
|
|
The Addict
Join Date: Nov 2007
Location: UK
Posts: 319
Thanks: 18
|
All you need is
PHP Code:
imagegif($image);
|
|
|
|
The Following User Says Thank You to Rendair For This Useful Post:
|
|
01-26-2008, 11:34 PM
|
#10 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
|
Quote:
Originally Posted by ReSpawN
You can also check out "The Big GD Guide - Part 1" in Salathe sig. 
|
Hmmm... I was just wondering if you realized that the guide you suggested is EXACTLY what I am reading and EXACTLY what is confusing me.
Last edited by Aaron : 01-27-2008 at 03:04 AM.
|
|
|
01-27-2008, 01:32 AM
|
#11 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
|
A friendly advice. Don't ever do this again:
Code:
header("Content-type: image/png");
imagejpeg($im);
If you send a header for a specific content-type, then, for god's sake, continue outputting that format. Don't send out a png header and output a JPEG image. It's wrong.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
|
|
|
|
|
The Following User Says Thank You to xenon For This Useful Post:
|
|
01-27-2008, 01:59 AM
|
#12 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
|
The GD article didn't say that :( It wasn't until I looked at the PHP documentation and saw all the functions that I saw that you could change all that stuff.
edit:
Yet another code that doesn't seem to work... Why does GD have to be so complicated?
PHP Code:
<?php header ("Content-type: image/png"); imagepng(imagecreatetruecolor(500, 500)); ?>
It was supposed to be a minimalist document, and it seems it doesn't work.
Last edited by Aaron : 01-27-2008 at 03:04 AM.
|
|
|
01-27-2008, 03:43 AM
|
#13 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
|
What exactly doesn't work? I, myself, thought at some point that GD was so god damn hard. But then I delved into it, and using just the php.net reference I was able to create a captcha system of my own (a very basic one, but it worked). So it isn't that hard. After that, more followed (like a simple graph system, some statistics generators and even an image manipulation library). You just need to get the point. And practice 
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
|
|
|
|
01-27-2008, 04:14 AM
|
#14 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
|
The code works now, It saved as a PNG by default...
Why use imagetruecolor instead of imagecreate?
:/ This stuff is confuzzling the me.
Can somone help me on this forums IRC channel? That would be a great help.
|
|
|
01-27-2008, 09:35 AM
|
#15 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
|
imagecreatetruecolor has a larger palette of colors, but doesn't support GIFs. Wow, does really this forum have an IRC channel? I think I'll join too (after I get a haircut)
PS: what's the address?
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
|
|
|
|
01-27-2008, 08:07 PM
|
#16 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
|
irc.chatwebdev #talkphp
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|