Getimagesize and imagepng()

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

Post Reply
Terriator
Forum Commoner
Posts: 60
Joined: Mon Jul 04, 2005 12:46 pm

Getimagesize and imagepng()

Post by Terriator »

Heya, I have a script which creates and saves an image:

Code: Select all

function  create_image(){
    
        // User data
        $message1 = 'TEXT';
        $message2 = 'TEXT';
        $message3 = 'TEXT';
        $message4 = 'TEXT';
        $message5 = 'TEXT';  
        
            
    $im = imagecreatefromgif("./images/signatures/default1.gif") or die("Cannot Initialize new GD image stream");
    $text = imagecolorallocate($im, 0, 0, 0);      // text colour
    imagestring($im, 2, 10,  23, $message1, $text);
    imagestring($im, 2, 10,  33, $message2, $text);
    imagestring($im, 2, 10,  43, $message3, $text);
    imagestring($im, 2, 10,  53, $message4, $text);
    imagestring($im, 2, 10,  63, $message5, $text);
        
    imagepng($im,"./images/signatures/".$_SESSION['uid'].".png");
    imagedestroy($im);
        
}
Afterwards, when I go to Vbulletin and enter: http://XXX/images/signatures/3819.gif I get following error:
Warning: getimagesize(http://XXX/images/signatures/3819.gif) [function.getimagesize]: failed to open stream: Connection timed out in /profile.php(1189) : eval()'d code on line 10
So, how to fix? =)
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Getimagesize and imagepng()

Post by VladSun »

1. Use local file "address" instead of http://XXX/images/signatures/3819.gif:
I mean:
getimagesize('./images/signatures//3819.gif');

2. You generate PNG files and then you try to read GIF files ...
There are 10 types of people in this world, those who understand binary and those who don't
Terriator
Forum Commoner
Posts: 60
Joined: Mon Jul 04, 2005 12:46 pm

Re: Getimagesize and imagepng()

Post by Terriator »

1. It's supposed to be an image that people can use on any forum; so it wouldn't work with a local address? Or am I stupid?

2. Sorry about that; because I tried out both the png and the gif function.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Getimagesize and imagepng()

Post by VladSun »

Perhaps your server firewall (the one with Vbulletin) doesn't allow outgoing connections.
Can you open http://XXX/images/signatures/3819.gif from your browser?
There are 10 types of people in this world, those who understand binary and those who don't
Terriator
Forum Commoner
Posts: 60
Joined: Mon Jul 04, 2005 12:46 pm

Re: Getimagesize and imagepng()

Post by Terriator »

Yep, works fine.. it's only the getimagesize function that doesn't like the image it seems.

Actually, it seems like it's not something related to the script perhaps, because any images I upload and try to view in my forum gets a timeout.

However, when I try to load the same images in different forums (this one, for example), it works fine ~___~
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Getimagesize and imagepng()

Post by VladSun »

It could happen if your forum is running on a DMZ server - i.e. you have a router which will forward all requests from Internet to your server. But it doesn't happen when a request on its internal interface is received. And this is the case when you try to open http://domain.com, because the resolved IP is actuallly the IP of the router.
There are 10 types of people in this world, those who understand binary and those who don't
Terriator
Forum Commoner
Posts: 60
Joined: Mon Jul 04, 2005 12:46 pm

Re: Getimagesize and imagepng()

Post by Terriator »

In other words: I modify my own forum's way of showing the images and it should then work on all others? (which I should of course check)
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Getimagesize and imagepng()

Post by VladSun »

I don't know what's your case but try replacing in your forum http://XXX/ with http://localhost/ and see if it works.
There are 10 types of people in this world, those who understand binary and those who don't
Terriator
Forum Commoner
Posts: 60
Joined: Mon Jul 04, 2005 12:46 pm

Re: Getimagesize and imagepng()

Post by Terriator »

Nope, doesn't..
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Getimagesize and imagepng()

Post by VladSun »

Terriator wrote:Nope, doesn't..
So, now you should have:
Warning: getimagesize(http://localhost/images/signatures/3819.gif) [function.getimagesize]: failed to open stream: Connection timed out in /profile.php(1189) : eval()'d code on line 10
error?
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply