GD - Picture not being shown

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

GD - Picture not being shown

Post by Straterra »

I have this code, but when you try to load the image, it won't load! I get a red X!

Code: Select all

<?php 
$val = file("imagecounter.txt"); 
$num = $val[0]; 
$num++; 
$fp = fopen( "imagecounter.txt", "w" ); 
fwrite( $fp, $num ); 
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']); 
header ("Content-type: image/png"); 
$img_handle = ImageCreate (400, 110) or die ("Cannot Create image"); 
$back_color = ImageColorAllocate ($img_handle, 0, 10, 10); 
$txt_color = ImageColorAllocate ($img_handle, 255, 255, 255); 
ImageTTFText ($img_handle, 9, 0, 5, 20, $txt_color, "/WINDOWS/Fonts/IMPACT.ttf", 
              "IP : ".$_SERVER['REMOTE_ADDR']); 
ImageTTFText ($img_handle, 9, 0, 5, 40, $txt_color, "/WINDOWS/Fonts/IMPACT.ttf", 
              "HostName : ".$hostname); 
ImageTTFText ($img_handle, 9, 0, 5, 60, $txt_color, "/WINDOWS/Fonts/IMPACT.ttf", 
              "Referer : ".$_SERVER['HTTP_REFERER']); 
ImageTTFText ($img_handle, 9, 0, 5, 80, $txt_color, "/WINDOWS/Fonts/IMPACT.ttf", 
              "User Agent : ".$_SERVER['HTTP_USER_AGENT']); 
ImageTTFText ($img_handle, 9, 0, 5, 100, $txt_color, "/WINDOWS/Fonts/IMPACT.ttf", 
              "You are viewer number $num"); 
ImagePng ($img_handle); 
?>
tsg
Forum Contributor
Posts: 142
Joined: Sun Jan 12, 2003 9:22 pm
Location: SE, Alabama
Contact:

Post by tsg »

What if you change:
ImageCreate (400, 110)

to
ImageCreatefrompng (400, 110)
User avatar
Derfel Cadarn
Forum Contributor
Posts: 193
Joined: Thu Jul 17, 2003 12:02 pm
Location: Berlin, Germany

Post by Derfel Cadarn »

Hey Straterra, isn't that the code you use in your signature here? Seems to work fine! :wink:
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

Yeah, that is the code..but when I try to view it in a browser, it doesn't work!
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

And TSG, it returns an error.
User avatar
Derfel Cadarn
Forum Contributor
Posts: 193
Joined: Thu Jul 17, 2003 12:02 pm
Location: Berlin, Germany

Post by Derfel Cadarn »

Do you mean you don't see the image when you visit this thread? Or when you run it from your own server? Can it have anything to dowith th fonts being not in that dir? :oops:
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

he means that it doesn't work when just viewing the image, which it doesn't for me either...
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Please remove that. You do not have permission to run additional scripts or attempt to set cookies for visitors to phpdn.
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

Wha? Remove...what? Cookies?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Your image link runs a script on your site. Your site attempts to set a cookie.

Please remove this.
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

Um...The website isn't mine, though I host it. The only file that I have is the draw.php, which draws the GD thing. It has no cookie..I don't know what you are talking about. What I posted is all to the code.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

For the third time, would you please remove this signature?
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

It doesn't use a cookie. Would you like me to send you the draw.php file? Because I will!
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Remove it now please.
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

What's your email? I will email you the file. No one else complains of it setting a cookie. I will look right now on this machine and see if it set a cookie.
Post Reply