• 0

Checking file size (fixed)


Question

Hey guys,

I'm working on my new signature image, and it incorporates information for the current song I'm listening to in itunes. One of the things it will display is the applicable album cover for the song.

Where I'm running into trouble is with:

<?php
  	//Get the album pic
  	if(isset($imageurl)) {
    $pic = imagecreatefromjpeg( $imageurl );
    ImageCopyResampled( $image, $pic, 428, 47, 0, 0, 50, 50, 50, 50 );
    imagedestroy( $pic ); 
  	} else {
    ImageTTFText($image, 6, 0, 430, 55, $clr_white, "verdana.TTF", wordwrap("No Image Found!", 12));
  	}
  	?>

Right now its set to know if the variable $imageurl is set. I run into problems when the image link is a dud or a blank. An example of this blank image output is:

http://images.amazon.com/images/P/B0006TIJNA.01.THUMBZZZ.jpg

And I get the following errors:

Warning: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: in /home/webusers/axonmedia/axonmedia.ca/www/itunes/itunes.php on line 183

Warning: imagecreatefromjpeg(): 'http://images.amazon.com/images/P/B0006TIJNA.01.THUMBZZZ.jpg' is not a valid JPEG file in /home/webusers/axonmedia/axonmedia.ca/www/itunes/itunes.php on line 183

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/webusers/axonmedia/axonmedia.ca/www/itunes/itunes.php on line 184

Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/webusers/axonmedia/axonmedia.ca/www/itunes/itunes.php on line 185

So I just want to know, how can I tell the size of the image? Any other suggestions?

Thanks,

-Ax

Edited by Axon
Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hmmm.... this may give you more server load then you want. But have you considered using fopen() to load the image from the URL, and then fwrite() to write that "binary stream" to a file? Then you can use stat() to get information about the file into an array, and check it's file size.

Seems like there should be a simpler way. You should check your "imagecreatefromjpeg" class to see if there is a method for finding the size of the file.

-nic

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.