Branches
Comments
[»]
updated script - autorotate images, no popup, etc.
by Peter T. Breuer - Sep 25th 2006 00:34:27
--- tigger.pl Tue Oct 30 23:54:24 2001
+++ /usr/local/bin/tigger Mon Sep 25 08:50:49 2006
@@ -17,7 +17,7 @@
use Image::Size;
# Globals
-$VERSION = '1.1';
+$VERSION = '1.2';
$RELEASED = 'October 30, 2001';
$COPYRIGHT = '2001';
$AUTHOR = 'Geoff Silver <geoff@uslinux.net>';
@@ -30,6 +30,8 @@
$MKDIR = `which mkdir 2> /dev/null`;
chomp($MKDIR);
$CONVERT = `which convert 2> /dev/null`; chomp($CONVERT);
$FILE = `which file 2> /dev/null`; chomp($FILE);
+# PTB need identify too
+$IDENTIFY = `which identify 2> /dev/null`; chomp($IDENTIFY);
if (! $LS) { print "Your system lacks the 'ls' program or 'ls' is
not in your path.\n"; exit 1; }
if (! $MV) { print "Your system lacks the 'mv' program or 'mv' is
not in your path.\n"; exit 1; }
@@ -37,6 +39,8 @@
if (! $MKDIR) { print "Your system lacks the 'mkdir' program or
'mkdir' is not in your path.\n"; exit 1; }
if (! $CONVERT) { print "Your system lacks ImageMagick or 'convert'
is not in your path.\n"; exit 1; }
if (! $FILE) { print "Your system lacks the 'file' program or 'file'
is not in your path.\n"; exit 1; }
+# PTB need identify too
+if (! $IDENTIFY) { print "Your system lacks the 'identify' program
or 'identify' is not in your path.\n"; exit 1; }
# Defaults
$compresslevel = 75;
@@ -46,11 +50,16 @@
$shadowdir = "/images";
$logfile = "tigger-errors.log";
$CELLWIDTH = 120;
+# PTB changed defaults
+$index = true;
+$thumbnail = true;
+$splitpages = "0";
# Get command line options
my $opts = &GetOptions( "compress" =>
\$compress,
- "thumbnail" => \$thumbnail,
- "index" => \$index,
+ # PTB use thumbnail and index by default
+ "nothumbnail" =>
\$nothumbnail,
+ "noindex" => \$noindex,
"level=s" =>
\$compression,
"thumbsize=s" =>
\$thumbnailsize,
"dropshadow" => \$shadow,
@@ -74,6 +83,10 @@
if ($version) { version(); exit 0; }
if ($changelog) { changelog(); exit 0; }
+# PTB recover original option variables
+if ($noindex) { $index = false; }
+if ($nothumbnail) { $thumbnail = false; }
+
# Do error checking
if (($thumbnailsize) && (! $thumbnail)) {
print "Syntax Error: --thumbsize requires
--thumbnail\n";
@@ -83,6 +96,7 @@
print "Syntax Error: --level requires --compress\n";
exit 1;
}
+
if ((($filename) || ($shadow) || ($splitpages) || ($section) || ($footer)
|| ($colwidth))
&& (! $index)) {
print "Syntax Error: --dropshadow, --section, --filename,
--cellwidth, and \n";
@@ -101,6 +115,10 @@
if ($archive) {
archive();
}
+
+# PTB rotate all images if necessary first of all
+rotate();
+
if ($imagesize) {
resize($imagesize);
}
@@ -113,7 +131,8 @@
thumbnail($thumbsize);
}
if ($index) {
- if ($splitpages) { $pagebreak = $splitpages; }
+ # PTB also disable pagebreak when cmdline splitpages = 0 is given
+ if ($splitpages || $splitpages eq "0") { $pagebreak =
$splitpages; }
if ($section) { $title = $section; }
if ($imagedir) { $shadowdir = $imagedir; }
if ($colwidth) { $CELLWIDTH = $colwidth; }
@@ -135,9 +154,9 @@
print " --compress - Compress large
images\n";
print " --level=<level> - Percent compression level
(default = 25)\n";
print " --imagesize=HxW - Resize large images to HEIGHT x
WIDTH\n";
- print " --thumbnail - Create thumbnails for
index\n";
+ print " --nothumbnail - Do not create thumbnails for
index\n";
print " --thumbsize=HxW - Size of thumbnails (default =
80x60)\n";
- print " --index - Create index.html pages for
images\n";
+ print " --noindex - Do not create index.html pages for
images\n";
print " --cellwidth=width - Column width (default =
120)\n";
print " --dropshadow - Add dropshadows to
images\n";
print " --imagedir=/dir - Specify path to directory
containing shadows\n";
@@ -145,7 +164,7 @@
print " --disclaimer=file - Add a disclaimer/copyright to each
index\n";
print " --filename - Print the image name below each
thumbnail\n";
print " --section=name - Title for index.html
pages\n";
- print " --splitpages=X - Split gallery every X images
(default = 25)\n";
+ print " --splitpages=X - Split gallery every X images
(default = 0)\n";
print " Enter 0 to not split
indexes.\n";
print " --logerrors - Log errors to a file (default =
tigger-errors.log\n";
print " --errorlog=file - Specify a different file to log
errors\n";
@@ -201,6 +220,21 @@
return(@words[0]);
}
+# PTB Check file orientation
+sub getfileorientation {
+ my ($file) = @_;
+ $fileorientation = `$IDENTIFY -format '%[EXIF: Orientation]' $file
2> $logfile`;
+ if ($fileorientation && $fileorientation != 1) {
+ $filedimensions = `$IDENTIFY -format "%wx%h" $file 2>
$logfile`;
+ ($fwidth, $fheight) = split(/x/, $filedimensions);
+ if ($fheight < $fwidth) {
+ return $fileorientation;
+ }
+ }
+ # PTB default 1 means it's the right way up
+ return 1;
+}
+
# Check if the file type is PNG, MIFF, or JPEG
sub iscompressable {
my ($type) = @_;
@@ -221,6 +255,16 @@
}
}
+# PTB rotate images
+sub rotate {
+ foreach $file (getfiles()) {
+ if (getfileorientation($file) != 1) {
+ `$CONVERT -rotate 90 "$file" temp 2> $logfile`;
+ `$MV -f temp "$file" 2> $logfile`;
+ }
+ }
+}
+
# Resize/Scale large images
sub resize {
my ($dimensions) = @_;
@@ -257,7 +301,8 @@
else { $backlink = "index.html"; }
print F "<tr><td align=left valign=top><a
href=\"$backlink\">Previous
$pagebreak</a></td>\n";
}
- print F "<td align=center valign=top colspan=3>Click on a
thumbnail to view a larger image version</td>\n";
+ # PTB this comment is silly
+ # print F "<td align=center valign=top colspan=3>Click on a
thumbnail to view a larger image version</td>\n";
if ($forwardlink) {
if ($file eq "index.html") {
$forwardlink = "index-1.html";
@@ -333,8 +378,9 @@
sub indexnoshadow {
my ($file, $j, @files) = @_;
+ # PTB remove target="new" so no popups
print F "<td width=$CELLWIDTH valign=top align=center><a
- href=\"$file\" target=\"new\"><img
src=\"thumbnails/@files[$j]\"
+ href=\"$file\"><img
src=\"thumbnails/@files[$j]\"
border=0></a>";
if ($printname) { print F "<br>$file"; }
print F "</td>\n";
@@ -346,12 +392,13 @@
($WIDTH, $HEIGHT, $IMAGETYPE) =
imgsize("thumbnails/$file");
$BWIDTH=$WIDTH-19;
$RHEIGHT=$HEIGHT-19;
+ # PTB remove target="new" so no popups
print F "<td width=$CELLWIDTH valign=top align=right>
<table border=0 cellspacing=0 cellpadding=0>
<tr> <!-- Image -->
<td align=right valign=bottom colspan=2 rowspan=2><a
- href=\"$file\" target=\"new\"><img
src=\"thumbnails/@files[$j]\"
+ href=\"$file\"><img
src=\"thumbnails/@files[$j]\"
border=0 height=$HEIGHT width=$WIDTH
alt=\"$file\"></a></td>
<!-- Top Right Shadow Corner -->
@@ -407,5 +454,9 @@
print " * Added the ability of users to change the default column
width (useful\n";
print " when working with very long file names and using the
--filename flag\n";
print " * Added the ability to archive originals before
processing\n";
+ print "Version 1.2: (2004/5/6) PTB\n";
+ print " * No popup for thumbnail\n";
+ print " * Thumbnails and index by default (and no page
limit)\n";
+ print " * Rotate portrait mode pix to vertical
automatically\n";
print "\n";
}
-- Peter T. Breuer MA CASM PhD (Ing.), Prof. Asoc.
Area de Ingenieria Telematica E-mail: ptb@inv.it.uc3m.es
Dpto. Ingenieria Tel: +34 (9)1 624 91 80
Universidad Carlos III de Madrid Fax: +34 (9)1 624 8749/9430
Butarque 15, Leganes/Madrid, E-28911 Spain
[reply]
[top]
|