#!/usr/bin/perl -w use strict; use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); use Image::Magick; #settings my $thumbs_width = 100; #thumbs's width my $thumbs_height = 100; #thumbs's height my $dir = 'E:/Fayland/Gallery'; #the to-do dir my $url = 'http://localhost/Gallery'; #the relevant url my $need_index = 1; # 1 - produce the index.html, 0 - ingore my $query = new CGI; print $query->header; my @gallery; (-d "$dir") or die "Cann't find $dir"; opendir(DIR,"$dir"); @gallery = readdir(DIR); closedir(DIR); @gallery = grep(/(gif|jpe?g|png)$/, @gallery); my $i; open(FH, ">$dir/index.html") if ($need_index); foreach (@gallery) { $_ =~ m/(.*)\.(.*)/; my $thumbsfile = "$1.png"; unless (-e "$dir/thumbs/$thumbsfile") { my $image=Image::Magick->new; my $x = $image->Read("$dir/$_"); warn "$x" if "$x"; $x = $image->Resize(width=>$thumbs_width, height=>$thumbs_height); $x = $image->Write("$dir/thumbs/$thumbsfile"); } print "$_"; print FH "$_" if ($need_index); $i++; if ($i % 5 == 0) { print "
"; print FH "
" if ($need_index); } } close(FH) if ($need_index); print "

Visit the IndexPage

" if ($need_index);