#!/usr/bin/perl # Filename: album # Author: David Ljung Madison # See License: http://MarginalHacks.com/License/ my $VERSION= 2.53; # Description: Makes a photo album use strict; use IO::File; #use locale; # Does Windows have this? umask 022; # 0755 ################################################## ################################################## # SETTINGS ################################################## ################################################## my $PROGNAME = $0; $PROGNAME =~ s|.*/||; # Windows users will probably want to specify full paths, such as: # my $CONVERT = 'C:/PROGRAM FILES/IMAGEMAGICK/convert.exe'; # my $IDENTIFY = 'C:/PROGRAM FILES/IMAGEMAGICK/identify.exe'; # Win98: Slightly different version #WIN98#$VERSION .= " (win98)"; # Win98: Needs TCAP: ftp://ftp.simtel.net/pub/simtelnet/msdos/sysutl/tcap31.zip #WIN98#my $TCAP = 'tcap'; #WIN98#my $TCAP_FILE = "atrash.tmp"; #WIN98## Put tcap args in the tcap env var, so to reduce line length (128 limit) #WIN98#$ENV{tcap}="-overwrite *${TCAP_FILE}"; my $CONVERT = "convert"; my $IDENTIFY = "identify"; # Undef if you don't have identify my $JHEAD = "jhead"; # Extract EXIF info from jpgs my $FFMPEG = "ffmpeg"; # For extracting movie frames # Default directory page my $HTML = ".html"; my $DEFAULT_INDEX = "index$HTML"; # Don't need to specify this index my $HEADER = "header.txt"; my $FOOTER = "footer.txt"; my $NO_ALBUM = ".no_album"; # Don't run album on these dirs/files my $HIDE_ALBUM = ".hide_album"; # Don't even show these directories my $NOT_IMG = ".not_img"; # Postfix for files that aren't images # Avoid "Broken pipe" messages $SIG{PIPE} = 'IGNORE'; ######################### # abs_path ######################### use Cwd 'abs_path'; # If you don't have the Cwd module, use this: #sub abs_path { # my ($dir) = @_; # my $pwd=`pwd`; chomp($pwd); # chdir($dir) || usage("Couldn't find [$dir]"); # my $name=`pwd`; chomp($name); # chdir($pwd); # $name; #} my %DEFAULTS = ( # Thumbnail stuff 'x' => 133, # Size of thumbnails 'y' => 100, 'crop' => 1, # Crop or just scale? 'CROP' => "", # top, bottom, left or right 'force' => 0, # Force thumbnail generation 'type' => "jpg", # Thumbnail image type 'medium_type' => "", # Medium Thumbnail image type 'dir' => "tn", # Thumbnail directory 'known_images' => 0, # I'd rather keep my album clean 'sample' => 0, # -sample:-geometry :: fast:better 'animated_gifs' => 0, # Use [0] in convert for animated gifs # Album stuff 'medium' => "", # Make medium size pictures? 'just_medium' => 0, # Don't link to full size images 'image_pages' => 1, # Page per image 'embed' => 1, # Use embed for non-pic image pages 'index' => $DEFAULT_INDEX, # Default index 'body' => "", # tag 'top' => "..", # The "Back" for the top album 'columns' => 4, # Number of images per row 'file_sizes' => 0, # Show image file sizes 'image_sizes' => 0, # Get image sizes (width*height) 'clean' => 0, # Clean garbage out of thumbnail dir? 'captions' => "captions.txt", # Captions filename? 'caption_edit' => 0, # Add tags for editing captions CGI 'exif' => "", # Format for EXIF caption string 'fix_urls' => 1, # Encode unsafe characters as %xx in URL 'depth' => -1, # Depth to descend directories 'add' => "", # Add these directories to the album 'all' => 0, # Do not hide .directories 'hashes' => 1, # Show hash progress marks 'name_length' => 40, # Limit length of image names 'date_sort' => 0, # Sort by date 'name_sort' => 0, # Sort by name, ignore caption order 'reverse_sort' => 0, # Reverse sorting 'charset' => "iso-8859-1",# Charset for default theme 'image_loop' => 1, # Do image pages loop around? # eperl stuff 'enter_eperl' => '<:', # Start code region in theme 'leave_eperl' => ':>', # Leave code region in theme # Ignore this stuff.. 'transform_url' => "", # Hack for transforming image URL # deprecated, it's automated now 'identify' => 1, # Use identify or convert for get_size? 'theme_url' => "", # In case we need to specify theme URL 'theme' => "", # So that -no_theme works, ignored. ); # As of "ImageMagick 4.2.9 99/09/01" # May not be the same as your version of convert, but damn it's alot! my $IMAGE_TYPES = "AVS|BMP|BMP24|CMYK|DCM|DCX|DIB|EPDF|EPI|EPS|EPS2|EPSF|EPSI|EPT|FAX|". "FITS|G3|GIF|GIF87|GRADATION|GRANITE|GRAY|HDF|HISTOGRAM|ICB|ICC|ICO|". "IPTC|JPG|JPEG|JPEG24|LABEL|LOGO|MAP|MATTE|MIFF|MNG|MONO|MPG|MPEG|MTV|NULL|P7|". "PBM|PCD|PCDS|PCL|PCT|PCX|PDF|PIC|PICT|PICT24|PIX|PLASMA|PGM|PM|PNG|". "PNM|PPM|PREVIEW|PS|PS2|PS3|PSD|PTIF|PWP|RAS|RGB|RGBA|RLA|RLE|SCT|SFW|". "SGI|SHTML|STEGANO|SUN|TEXT|TGA|TIF|TIFF|TIFF24|TILE|TIM|TTF|TXT|UIL|". "UYVY|VDA|VICAR|VID|VIFF|VST|X|XBM|XC|XPM|XV|XWD|YUV"; $IMAGE_TYPES.="|AVI|MOV|MOOV" if $FFMPEG; # ffmpeg can handle AVI, MOV ######################### # Windows blows ######################### my $OSX = ($^O =~ /darwin/i) ? 1 : 0; my $CRAPPY_OS = (!$OSX && ($^O =~ /Win/i)) ? 1 : 0; # Win98=MSWin, WinXP=MSWin (damn), CygWin=cygwin # 1) Can't handle "\Qfile\E"; sub file_quote { my ($file) = @_; $CRAPPY_OS ? "\"$file\"" : "\Q$file\E"; } # 2) Can't create .files $NO_ALBUM =~ s/^\.//g if $CRAPPY_OS; $HIDE_ALBUM =~ s/^\.//g if $CRAPPY_OS; # 3) Stupid $0 is probably '/' not '\' if ($CRAPPY_OS && $0 =~ m|\\|) { # Guess $PROGNAME = $0; $PROGNAME =~ s|.*\\||; } # 4) Can't handle 'open(FOO,"cmd |")' or 2>&1 # (According to one mail, 2>&1 works in Win2000) sub open_pipe { my ($cmd) = @_; print STDERR "run: $cmd\n" if ($MAIN::DEBUG); my $fh = new IO::File; # Happy Unix return (open($fh, "$cmd 2>&1 |")) && $fh unless $CRAPPY_OS; # Win98 (use TCAP) #WIN98# system("$TCAP -c $cmd"); #WIN98# (open($fh, "$TCAP_FILE")) || die("Can't open $TCAP output [$TCAP_FILE]\n"); #WIN98# return $fh; # Windows2000,XP: -| pipe method, doesn't seem to work on Win98 my $pid = (open($fh,"-|")); return undef unless defined $pid; # Failed return $fh if $pid; # Parent # Child (open(STDERR,">&STDOUT")) || die("open_pipe(): Can't dup stdout\n"); exec($cmd); } # 4 1/2) Clean up the tmp file (for Win98) #WIN98# sub win_done { print STDERR "@_\n"; unlink($TCAP_FILE); exit; } #WIN98# if ($CRAPPY_OS) { #WIN98# $SIG{INT} = \&win_done; $SIG{TERM} = \&win_done; #WIN98# $SIG{HUP} = \&win_done; $SIG{QUIT} = \&win_done; #WIN98# $SIG{EXIT} = \&win_done; $SIG{__DIE__} = \&win_done; #WIN98# } # 5) Can't handle /dev/null? # (Need to figure this out - make a tmpfile? $DEV_NULL = ...?) # 6) .exe extension if we don't have it if ($CRAPPY_OS) { $CONVERT =~ s/\.exe$//; $IDENTIFY =~ s/\.exe$//; $CONVERT .= ".exe"; $IDENTIFY .= ".exe"; } ######################### # URLs for these scripts - don't change ######################### my $HOME = "http://MarginalHacks.com/"; my $ALBUM_URL = "${HOME}Hacks/album/"; my $GEN_STRING = "album $HOME"; my $OLD_GEN_RE = "Generated by $PROGNAME and thumb"; ######################### # Stupid privoxy bug. ######################### sub concat { die(<\n"; print "\tMakes a photo album\n"; print "\n"; print "\tAll boolean options can be turned off with '-no_