#!/usr/local/bin/perl # This is to be run in the directory containing the large, # medium, and small directories. If there are any .jpg # files here, they will be moved to the "large" directory. # The medium and small directorys will be emptied, and, # refilled with resized pics. 3 .htm files will be # created. Be cautious with the large.htm as it creates a # page with all the unshrunk pics. # # 1 Question will be asked of you!!!!!!!!!!!!!!!!!!!!!! # This will be used to create the page title. print "On the next line, enter a Title for the Web Page. Like..\n April 2004 Our Visit with Bart Simpson\n"; $the_title_line = ; chop $the_title_line; if ( "$the_title_line" !~ /\w/ ) {$the_title_line = "Our Visit with Bart Simpson";} # this is not working print "Thanks, the title will be..\n"; print "\n$the_title_line\n\n"; opendir (THIS_DIR, ".") || die "Couldn't open this directory.\n"; if ( ! -d "./large" ) { mkdir "./large"; } if ( ! -d "./medium") { mkdir "./medium"; } if ( ! -d "./small" ) { mkdir "./small"; } if ( ! -d "./large" ) { die "Problems with ./large";} if ( ! -d "./medium") { die "Problems with ./medium";} if ( ! -d "./small" ) { die "Problems with ./small";} opendir (MEDIUM_DIR, "./medium") || die "Couldn't open ./medium.\n"; opendir (SMALL_DIR, "./small") || die "Couldn't open ./small.\n"; foreach $foo ( readdir MEDIUM_DIR ) { if (($foo ne ".") && ($foo ne "..")) {unlink "./medium/${foo}"; }} foreach $foo ( readdir SMALL_DIR ) { if (($foo ne ".") && ($foo ne "..")) {unlink "./small/${foo}"; }} @this_dir_names = readdir THIS_DIR; foreach $foo ( @this_dir_names ) { if (($foo =~ /\.jpg$/) || ($foo =~ /\.JPG$/)) { #print "A match on ${foo}\n"; $foo = remove_spaces ("$foo"); if ( -f "./large/${foo}" ) { if ( compare_files("./large/${foo}", "${foo}") ) { print "./large/${foo} and ./${foo} differ!!!\n\n"; ${foo} =~ /.[jJ][pP][gG]/; ($root_name, $suffix_name) = ($`, $&); $root_name = "$root_name" . "_a"; $full_name = "$root_name" . "$suffix_name"; while ( -f "./large/$full_name" ) { $root_name = "$root_name" . "a"; $full_name = "$root_name" . "$suffix_name"; } print "Doing this.. rename (./${foo}, ./large/${full_name}\n"; rename ("./${foo}", "./large/${full_name}"); } else { print "./${foo} is identical to ./large/${foo}, so I'm deleting ./${foo}\n"; unlink $foo; } } else { rename ("./${foo}", "./large/${foo}"); } } } opendir (LARGE_DIR, "./large") || die "Couldn't open ./large.\n"; @large_file_names = readdir LARGE_DIR; foreach $foo (@large_file_names) { remove_spaces ("./large/$foo"); } closedir (LARGE_DIR); ## Now, everything is in place for easy_thumbs to shrink the ## files from larger, into medium and small directories. ## Check for existance of easy_thumbs !!!!!!!!!!!!!!!! $ret_val = system ('"c:\Program Files\Easy Thumbnails\EzThumbs.exe" ".\large\*.jpg;*.JPG" /D=small /M /P=_sm /W=120 /H=120 /Z=BestFit /F=Smart /Q=90 /Log="ez_thumb.log"'); if ("$ret_val" eq "0") {print "Created small sized pictures\n";} else {print "Problem creating small sized pictures. EzThumbs return value is $ret_val\n";} $ret_val = system ('"c:\Program Files\Easy Thumbnails\EzThumbs.exe" ".\large\*.jpg;*.JPG" /D=medium /M /P=_med /W=640 /H=640 /Z=BestFit /F=Smart /Q=90 /Log="ez_thumb.log"'); if ("$ret_val" eq "0") {print "Created medium sized pictures\n";} else {print "Problem creating medium sized pictures. EzThumbs return value is $ret_val\n";} #/Z BestFit | EnlargeToFit | NoResize | ShrinkToFit | StretchToFit #/F Filter type #/Q is from 1 to 100 to specify jpeg quality #/B is from -100 to +100 and adjusts brightness #/C is from -100 to +100 and adjusts contrast #/S is from -100 to +100 and adjusts sharpness #/R is from -180 to +180 and adjusts rotation #/HTML= #/T= goes into /D directory #/LIST= #/L to convert image names to lowercase in the web page #/M Display a pop-up of the number of files created #/Log= #/OnlyHtml ## Lastly, create the .htm files opendir (LARGE_DIR, "./large") || die "Couldn't open ./large.\n"; @large_file_names = readdir LARGE_DIR; @large_file_root; @large_file_suffix; $count = 0; foreach $foo (@large_file_names) { if ( $foo =~ /.jpg$/ ) { ($large_file_root[$count], $large_file_suffix[$count]) = ($`, $&); $count = $count + 1; } if ( $foo =~ /.JPG$/ ) { ($large_file_root[$count], $large_file_suffix[$count]) = ($`, $&); $count = $count + 1; } } #print "Count is $count, last element of root is $#{large_file_root}, suffix is $#{large_file_suffix} \n"; open (MED_HTM, ">pictures_medium.htm") || die "couldn't create pictures_medium.htm (aborting)\n"; open ( SM_HTM, ">pictures_small.htm") || die "couldn't create pictures_small.htm (aborting)\n"; $string = "\n\n${the_title_line}\n\n\n"; print(MED_HTM $string); print( SM_HTM $string); $string = '' . "\n" . '' . "\n" . '
' . "\n" . "

${the_title_line}

\n"; print(MED_HTM $string); print( SM_HTM $string); print(MED_HTM "

(medium sized pictures)

\n"); print( SM_HTM "

(small sized pictures)

\n"); print(MED_HTM "

Switch to thumbnail-sized picture page\n

\n"); print( SM_HTM "

Switch to medium-sized picture page\n

\n"); print(SM_HTM "\n"); $col = 1; #picture loop foreach $num (0..${count}-1) { $fm = "$large_file_root[$num]" . "_med" . "$large_file_suffix[$num]"; $fs = "$large_file_root[$num]" . "_sm" . "$large_file_suffix[$num]"; $fl = "$large_file_root[$num]" . "$large_file_suffix[$num]"; if ( -f "medium/$fm" ) { print(MED_HTM "

$fm
$fm
\n");} else { print(MED_HTM "

medium/$fm is missing
\n");} if ( -f "small/$fs" ) { print(MED_HTM "small       ");} print(MED_HTM "large

\n"); if ( -f "small/$fs" ) { print(SM_HTM "\n"); if ("$col" eq "3") { $col = 1; print(SM_HTM "\n\n"); } else { $col = $col + 1; } } print(SM_HTM "
$fs
$fs
\n");} else { print(SM_HTM "
small/$fs is missing
\n");} if ( -f "medium/$fm" ) { print(SM_HTM "medium       ");} print(SM_HTM "large
\n"); $string = "\n

These picture pages have been created by one of Biller's nifty scripts.\n" . "\n"; print(MED_HTM $string); print(SM_HTM $string); sub compare_files { my ($file1, $file2) = @_; open (FILE1, "<$file1")|| die "couldn't open ${file1}\n"; open (FILE2, "<$file2")|| die "couldn't open ${file2}\n"; @file1_lines = ; @file2_lines = ; if ($#file1_lines ne $#file2_lines) {return ("1")}; while ($file1_lines[0]) { if ($file1_lines[0] ne $file2_lines[0]) { return ("1");} shift (@file1_lines); shift (@file2_lines); } return("0"); } sub remove_spaces { my ($infile) = @_[0]; $outfile = $infile; if ( "$infile" =~ / / ) { # space found in name; let's remove it $outfile =~ tr/ /_/s; rename ("$infile", "$outfile"); } #print "Infile is $infile\nOutfile is $outfile\n\n"; return ("$outfile"); } exit(0); # Junk snipits follow @pl_files = grep (/\.pl$/, @this_dir_names); print "\nnow for only .pl files\n"; foreach $foo ( @pl_files ) { print "${foo}\n";} print "\nnow for the directory stats\n"; @stats = stat(THIS_DIR); foreach $foo ( @stats ) { print "${foo}\n";} open (AFILE, $pl_files[3]); print "\nnow for the file stats for $pl_files[3]\n"; @stats = stat(AFILE); foreach $foo ( @stats ) { print "${foo}\n";}