#!/usr/bin/perl -w # webwrap - doom@kzsu.stanford.edu # Mon Jun 9 18:14:44 2003 =head1 NAME webwrap =head1 SYNOPSIS mkdir <>/images cp *.jpg <>/images cd <>/images rename *.JPG *.jpg cp Orig/* . # Note: still down in "images" image_rescale -s `pwd` -a `pwd`/Orig -h 600 -w 850 cd .. thumbnailer -s 200 -t 0.15 images/*.jpg cp index.html index-old.html webwrap ((manually edit html, if desired)) =head1 DESCRIPTION Crunch through image files named according to a special format like so: A-golden_turkey-060203-018.jpg B-silver_swain-060203-019.jpg C-lead_baloon-060203-020.jpg And generate some simple web page wrappers to display them. The hyphen-separated fields of the name format mean: A - arbitrary code added to sort images in order (A, B, C...) golden_turkey - short description of the image, which *must* be unique 060203 - date in 'merkin format ((I don't know if this is used for anything)) 009 - arbitrary string (for me, whatever the digital camera called the image) Note, the "short description" has to be unique because it will get used as an html file name, and this script isn't bright enough to avoid a name collision. The short description also get's turned into a an image title inside of the html file: "golden_turkey" => "Golden Turkey". =cut use strict; use Image::Magick; use POSIX qw(strftime); use Cwd; my ($pwd, $imgpat, $project_title, $head, $index_head, $tail, @images, $i, $input_file, $seq, $rawtitle, $date, $numb, $spaceytitle, $prev_basename, $next_basename, $table, $prevfile, $nextfile, $width, $height, $bod); $pwd = cwd(); $imgpat = '(?i)\.jpg$|\.jpeg|\.png$'; ($project_title) = ($pwd =~ m{/([^/]*?)$}); # Use current directory name as main title $project_title = spaceout_title($project_title); $index_head = define_index_head( $project_title ); $tail = define_tail(); open DEX, ">index.html" or die "Couldn't open index.html\n: $!"; print DEX $index_head; opendir(IMG, "$pwd/images") or die "Can't find 'images' location inside of $pwd: $!"; @images = sort grep { m{$imgpat}o } readdir(IMG); # foreach $input_file (@images){ for($i=0; $i<=$#images ; $i++) { $input_file = $images[$i]; ($seq, $rawtitle, $date, $numb) = split /-/, $input_file; $spaceytitle = spaceout_title($rawtitle); # add an entry to the main index.html for this image $table = define_tab($spaceytitle, $rawtitle, $input_file); print DEX $table; # Now generate the wrapper html for the image if ($i == 0) { $prev_basename = "index"; } else { $prevfile = $images[$i-1]; (undef, $prev_basename, undef, undef) = split /-/, $prevfile; } if ($i == $#images) { $next_basename = "index"; } else { $nextfile = $images[$i+1]; (undef, $next_basename, undef, undef) = split /-/, $nextfile; } open FILE, ">$rawtitle.html" or die "Couldn't open $rawtitle.html\n: $!"; $head = define_head("$spaceytitle"); ($width, $height) = get_image_dims("images/$input_file"); # Would be better if labels "Previous" and "Next" changed to "Main index" when that's where it goes. $bod = < Previous Top

Next Top
BOD_WELL print FILE $head; print FILE $bod; print FILE $tail; close(FILE); } print DEX $tail; close(DEX); sub define_head { my $title = shift; my $datestamp = strftime("%B %e, %Y", localtime); my $block = < $title

$title

BLOCK_HEAD return $block; } sub define_index_head { my $title = shift; my $datestamp = strftime("%B %e, %Y", localtime); my $block = < $title

$title

$datestamp
BLOCK_HEAD_INDY return $block; } sub define_tail { my $addy = 'doom@kzsu.stanford.edu'; my $block = < $addy BLOCK_TAIL return $block } sub define_tab { my $title = shift; my $basename = shift; my $filename = shift; my $imogine="images/thumbnails/$filename"; my ($width, $height) = get_image_dims($imogine); my $block = < $title BLOCK_TAB } sub get_image_dims { my $input_file = shift; my $image = Image::Magick->new; my $err = $image->Read($input_file); warn "$err" if "$err"; my ($width, $height) = $image->Get('width', 'height'); return ($width, $height); } sub spaceout_title { my $rawtitle = shift; my $spaceytitle = join ' ', map {ucfirst} split /_/, $rawtitle; return $spaceytitle; } __END__ =head1 TODO Use a real html template package. Possibly redesign in an OOP form, inherit image objects from Image::Magick, and adds my own accessors for "basename" and so on. Add methods to do things like print-out the table wrapper for a thumbnail. =head1 AUTHOR Joseph Brenner, Edoom@kzsu.stanford.eduE =head1 COPYRIGHT AND LICENSE Copyright (C) 2004 by Joseph Brenner This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.2 or, at your option, any later version of Perl 5 you may have available. =head1 BUGS None reported... yet. =cut