get imagex and imagey

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
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

get imagex and imagey

Post by SidewinderX »

I am trying to get the width and height of a remote image. I would like to do this without generating the image in GD because the user can upload any image [ gif, png, jpg...]and I really don't feel like writing a case for each image [ if png use imagecreatepng ]

I wrote this function, but it throws warnings:

Code: Select all

function checkBanner($banner) {
	$binary_data = file_get_contents($banner);
	$im = imagecreatefromstring($binary_data);
	$width = imagesx($im);
	$height = imagesy($im);

	if($width > 410){
		return true;
	}

	else if($height > 70) {
		return true;
	}

	return false;
}
Where banner is a remote image link. Here is the error i receive:
Warning: file_get_contents() [function.file-get-contents]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/toplist/register.php on line 144

Warning: file_get_contents(http://graphics.domain.com/link_banner/400x60.gif) [function.file-get-contents]: failed to open stream: No such file or directory in /var/www/toplist/register.php on line 144

Warning: imagecreatefromstring() [function.imagecreatefromstring]: Empty string or invalid image in /var/www/toplist/register.php on line 145

Warning: imagesx(): supplied argument is not a valid Image resource in /var/www/toplist/register.php on line 146

Warning: imagesy(): supplied argument is not a valid Image resource in /var/www/toplist/register.php on line 147
Any ideas what I'm doing wrong?

Thanks.
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post by SidewinderX »

I'm pretty sure it is because the website has hot link protection. This works for other images. I'm pretty sure this is [ SOLVED ] unless someone wants to tell me how I can get around the hot link protection.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Yes, the failure of getaddrinfo is due to the page that you are after being unavailable.
Post Reply