Lu.#!/usr/bin/perl use strict; use warnings; use utf8; use Image::Magick; my $dir = $ENV{'PWD'}; chomp(my @files = `ls $dir`); if (-e "$dir/thumbs") { print STDERR "The directory $dir/thumbs already exists. Files inside + may be replaced.\n Do you want to continue ? (y/n)"; chomp(my $choice = <STDIN>); if ($choice =~ /^n/) { print STDERR "Aborted by user.\n"; exit(1); } else { if (!($choice =~ /^y/)) { print "Please enter 'y' or 'n' :"; } } } mkdir "$dir/thumbs" || die "Unable to create directory $dir/thumbs :$! +"; if (!(-e "$dir/index.html")) { open (OUT, ">:utf8", "index.html") || die "Unable to open file $dir/ +index.html : $!" } print OUT <<HERE; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w +3.org/TR/xhtml1/xhtml1-strict.dtd"> <html encoding="utf8"> <head> </head> <body> <h1>Contents of directory $dir</h1> HERE foreach my $file (@files) { if ($file =~ /\.(jpg|jpeg|bmp|gif|png)/) { my $image = Image::Magick->new(); $image->Read($file); $image->Resize('150x150'); $image->Write("thumbs/t_$file"); print OUT "<a href=\"$file\"><img src=\"thumbs/t_$file\"></a>\n"; } } print OUT "\n</body>\n</html>\n"; close OUT;
In reply to Re: thumbnails generator
by Lu.
in thread thumbnails generator
by spx2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |