TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   GD library... Oh god the errors... (http://www.talkphp.com/absolute-beginners/2104-gd-library-oh-god-errors.html)

Aaron 01-26-2008 07:53 PM

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.

ReSpawN 01-26-2008 07:59 PM

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


Aaron 01-26-2008 08:46 PM

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?

sjaq 01-26-2008 09:21 PM

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..

ReSpawN 01-26-2008 09:51 PM

Quote:

Originally Posted by sjaq (Post 9702)
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 );

Salathe 01-26-2008 10:12 PM

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.

ReSpawN 01-26-2008 10:17 PM

You can also check out "The Big GD Guide - Part 1" in Salathe sig. ;-)

Orc 01-26-2008 11:08 PM

Quote:

Originally Posted by ReSpawN (Post 9711)
You can also check out "The Big GD Guide - Part 1" in Salathe sig. ;-)

Which also uses GD!

Rendair 01-26-2008 11:08 PM

All you need is

PHP Code:

imagegif($image); 


Aaron 01-26-2008 11:34 PM

Quote:

Originally Posted by ReSpawN (Post 9711)
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.

xenon 01-27-2008 01:32 AM

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.

Aaron 01-27-2008 01:59 AM

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.

xenon 01-27-2008 03:43 AM

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 :-P

Aaron 01-27-2008 04:14 AM

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.

xenon 01-27-2008 09:35 AM

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) :-D

PS: what's the address?

Aaron 01-27-2008 08:07 PM

irc.chatwebdev #talkphp


All times are GMT. The time now is 08:15 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0