| Category: | CGI Programming |
| Author/Contact Info | /msg cjf |
| Description: | Simple little script that reads through a directory, grabs all files with png/jpg/gif extensions and prints them to the browser. |
#!/usr/bin/perl -wT
use strict;
use CGI;
use Image::Size;
my $q = new CGI;
my $imageDir = "./";
my @images;
opendir DIR, "$imageDir" or die "Can't open $imageDir $!";
@images = grep { /\.(?:png|gif|jpg)$/i } readdir DIR;
closedir DIR;
print $q->header("text/html"),
$q->start_html("Images in $imageDir"),
$q->p("Here are all the images in $imageDir");
foreach my $image (@images) {
my ($width, $height) = imgsize("$image");
print $q->p(
$q->a({-href=>$image},
$q->img({-src=>$image,
-width=>$width,
-height=>$height})
)
);
}
print $q->end_html;
Update: Applied gav^'s and dws's suggestions listed below. Update: Included jarich's code to use CGI.pm to print out the lines in the foreach loop. |
|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Display all images in a given directory
by gav^ (Curate) on Feb 02, 2002 at 03:55 UTC | |
by cjf (Parson) on Feb 02, 2002 at 04:22 UTC | |
|
Re: Display all images in a given directory
by merlyn (Sage) on Feb 02, 2002 at 14:54 UTC | |
|
Re: Display all images in a given directory
by dws (Chancellor) on Feb 02, 2002 at 03:56 UTC | |
by cjf (Parson) on Feb 02, 2002 at 04:29 UTC | |
|
Re: Display all images in a given directory
by rjray (Chaplain) on Feb 12, 2002 at 03:14 UTC |