Jump to content

Archived

This topic is now archived and is closed to further replies.

impeccable_nice

Problems in Working with GD library

Recommended Posts

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

Share this post


Link to post
Share on other sites
Posting up your code might be a good idea ;)

Share this post


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

Share this post


Link to post
Share on other sites
Ok, reading back through your original post, I'm not following you 100%. So lets clear this up...

Originally, you used your code [i]without[/i] 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"/>

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
How are you invoking the script?

Ken

Share this post


Link to post
Share on other sites
Put this in a page, and give us the result.
[code]
echo('<pre>');
print_r(gd_info());
echo('</pre>');
[/code]

This should give us some info about how GD is set up.

Share this post


Link to post
Share on other sites
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] =>
)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.