Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Display all images in a given directory

by rjray (Chaplain)
on Feb 12, 2002 at 03:14 UTC ( [id://144772]=note: print w/replies, xml ) Need Help??


in reply to Display all images in a given directory

It's nice to see Image::Size getting some play :-)

Rather than rely on the file name's extension, you could just loop over all the files through the imgsize call. Those that don't map to a known image type will return an error of the form "Data stream is not a known image file format" in the third element of the returned array. If it is an image, the 3-letter acronym for the type will be in the 3rd element. You could then actually note which files are images, but not displayable by browsers (such as TIF, BMP, etc.).

OR, if you aren't interested in files that are not GIF, JPG or PNG, you could eliminate the use of $width and $height completely, by using the attr_imgsize call:

use Image::Size 'attr_imgsize'; ... $q->img({-src => $image, attr_imgsize($image))

--rjray

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://144772]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-19 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found