in reply to determining image size by a URL

From the Image::Size documentation:

imgsize(stream)
Returns a three-item list of the X and Y dimensions (width and height, in that order) and image type of stream. Errors are noted by undefined (undef) values for the first two elements, and an error string in the third. The third element can be (and usually is) ignored, but is useful when sizing data whose type is unknown.

So, you're going to want to look in the third element returned to see what went wrong.

Replies are listed 'Best First'.
Re^2: determining image size by a URL
by Anonymous Monk on Jul 07, 2006 at 17:55 UTC
    Thanks for that, I passed a third arguement $error and now ALL the errors are the same Data stream is not a known image file format but I don't see how that is. All the images are JPG files with full URLs.

    For example http://images.imagefap.com/images/full/9/144/1448694657.jpg returns with that error (it's a clean picture). What could cause this error then? Could the server possibly loaded too slow and it timed out?

      Print the stream out to a file, and look at it -- it may be that what you see in a web browser is different from what the program sees, due to browser sniffing techniques, content negotiation, etc.

      Just because you get an image in your web browser doesn't mean that your program's going to get an image. (they don't look to have a robots.txt, but it's possible they have some other way of slowing down requests hitting their server too quickly)

      Could be due to a bug in Image::Size or in your code. Is imgsize() always returning three values? If not, only $width and $height are set by the assignment, and $error remains unchanged if there was no error. Try setting $error explicitely to '' before calling imgsize().