TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-26-2008, 07:53 PM   #1 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default GD library... Oh god the errors...

PHP Code:
<html>
<head>
<title>Using the GD Library</title>
</head>
<body bgcolor="Gray">
<?php
$im 
imagecreate(11020);
$white imagecolorallocate($im255255255);
$string imagestring($im155,  "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.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 01-26-2008, 07:59 PM   #2 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

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(10030);

// white background and blue text
$bg imagecolorallocate($im255255255);
$textcolor imagecolorallocate($im00255);

// write the string at the top left
imagestring($im500"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"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
The Following User Says Thank You to ReSpawN For This Useful Post:
Aaron (01-26-2008)
Old 01-26-2008, 08:46 PM   #3 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

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($image25500);
$string imagestring($image500"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?
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 01-26-2008, 09:21 PM   #4 (permalink)
The Acquainted
 
sjaq's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 113
Thanks: 11
sjaq is on a distinguished road
Default

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..
sjaq is offline  
Reply With Quote
Old 01-26-2008, 09:51 PM   #5 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

Quote:
Originally Posted by sjaq View Post
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"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 01-26-2008, 10:12 PM   #6 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

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.
Salathe is offline  
Reply With Quote
Old 01-26-2008, 10:17 PM   #7 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

You can also check out "The Big GD Guide - Part 1" in Salathe sig.
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 01-26-2008, 11:08 PM   #8 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by ReSpawN View Post
You can also check out "The Big GD Guide - Part 1" in Salathe sig.
Which also uses GD!
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 01-26-2008, 11:08 PM   #9 (permalink)
The Addict
Upcoming Programmer Top Contributor 
 
Rendair's Avatar
 
Join Date: Nov 2007
Location: UK
Posts: 319
Thanks: 18
Rendair is on a distinguished road
Default

All you need is

PHP Code:
imagegif($image); 
__________________
www.jooney.co.uk - the online portfolio
Send a message via MSN to Rendair
Rendair is offline  
Reply With Quote
The Following User Says Thank You to Rendair For This Useful Post:
Aaron (01-27-2008)
Old 01-26-2008, 11:34 PM   #10 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

Quote:
Originally Posted by ReSpawN View Post
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.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 01-27-2008, 01:32 AM   #11 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

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.
xenon is offline  
Reply With Quote
The Following User Says Thank You to xenon For This Useful Post:
Aaron (01-27-2008)
Old 01-27-2008, 01:59 AM   #12 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

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(500500));
?>
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.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 01-27-2008, 03:43 AM   #13 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

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.
xenon is offline  
Reply With Quote
Old 01-27-2008, 04:14 AM   #14 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

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.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 01-27-2008, 09:35 AM   #15 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

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.
xenon is offline  
Reply With Quote
Old 01-27-2008, 08:07 PM   #16 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

irc.chatwebdev #talkphp
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 10:03 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design