Jump to content


Photo

Problems in Working with GD library


  • Please log in to reply
9 replies to this topic

#1 impeccable_nice

impeccable_nice
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 13 July 2006 - 07:33 AM

hello,

  I have configured my GD library with PHP 4.3.2. But when I coded my first program which are using the resources provided by GD (infact that was just a simple rectangle). I could not see the desired output instead I have seen some letters on my browser. well I passed my own PNG header at the start of my code but I dont know why I could not see the rectangle, If you know then plz reply  ASAP

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 13 July 2006 - 07:37 AM

Posting up your code might be a good idea ;)

#3 impeccable_nice

impeccable_nice
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 13 July 2006 - 10:50 AM

1: <?php
2: header("Content-type: image/png");
3: $image = imagecreate( 200, 300 );
4: $red = imagecolorallocate( $image, 255, 0, 0 );
5: imagepng($image);
6: ?>



#4 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 13 July 2006 - 12:00 PM

Ok, reading back through your original post, I'm not following you 100%. So lets clear this up...

Originally, you used your code without the header and your browser returned a bunch of text.
Then, you added the header and your browser returned the expected image.
You want to know why it does not work as expected without the header?

It does this as there is nothing telling the browser that it is an image, it's opening it as a plain text file I guess and unable to decode it correctly as it's not actually plain text. Therefore you add the header to tell the browser what to expect the file output to be. An alternative is to remove the header, and reference the file as an image in another script with the image tag: <img src="imagescript.php" alt="" border="0px"/>

#5 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 13 July 2006 - 12:02 PM

wat are u trying to do, create a validation image or something?

#6 impeccable_nice

impeccable_nice
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 13 July 2006 - 05:14 PM


NO NO you are not getting my point . I know the story behind sending headers I sent my own header at line 2 which you can see but still I cant see the expected result (i-e a rectangle). So If you know what the problem realy is then plz reply ASAP.

I am not creating any anti spam key image, I just only want to check whether my GD library is properly working or not.

#7 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 13 July 2006 - 05:30 PM

How are you invoking the script?

Ken

#8 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 13 July 2006 - 08:42 PM

Put this in a page, and give us the result.
echo('<pre>');
print_r(gd_info());
echo('</pre>');

This should give us some info about how GD is set up.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#9 impeccable_nice

impeccable_nice
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 15 July 2006 - 10:39 AM

Array
(
  [GD Version] => bundled (2.0.12 compatible)
  [FreeType Support] => 1
  [FreeType Linkage] => with freetype
  [T1Lib Support] =>
  [GIF Read Support] => 1
  [GIF Create Support] =>
  [JPG Support] => 1
  [PNG Support] => 1
  [WBMP Support] => 1
  [XBM Support] => 1
  [JIS-mapped Japanese Font Support] =>
)



#10 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 15 July 2006 - 11:19 AM

Put it on the page with an an IMG tag, just as would any other image.

If your script is "red_rect.php" then

<img src='red_rect.php'>

PS and use imagedestroy($image) at end to release memory used by image
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users