summaryrefslogtreecommitdiffabout
authorAndy Shevchenko <andy@smile.org.ua>2006-08-19 10:44:59 (GMT)
committer Andy Shevchenko <andy@smile.org.ua>2006-08-19 10:44:59 (GMT)
commitb22a6adc5a4b5adb5b6372675d417864d3c2351b (patch) (side-by-side diff)
tree60882ad8f568e6ddab03141ec92dd4bfb8315151
parent97daff9a3404219369d46e6fe829db1edb316849 (diff)
downloadrenrot-b22a6adc5a4b5adb5b6372675d417864d3c2351b.tar.gz
renrot-b22a6adc5a4b5adb5b6372675d417864d3c2351b.tar.bz2
Now Win32 platform is considered in parseConfig(), the variable USERPROFILE instead of HOME.
Add IPC support for rotating thumbnails. git-svn-id: file:///svnroot/renrot/branches/RENROT_STABLE@245 fe2816f4-e837-0410-b10a-f608c9d244a1
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ChangeLog5
-rw-r--r--etc/renrot.conf4
-rwxr-xr-xrenrot107
3 files changed, 97 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index 00197ba..1536521 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,8 @@
$Log$
+Revision 1.148.2.2 2006/08/19 10:44:59 andy
+Now Win32 platform is considered in parseConfig(), the variable USERPROFILE instead of HOME.
+Add IPC support for rotating thumbnails.
+
Revision 1.148.2.1 2006/08/19 06:27:25 andy
Add original file name counter template sequence "%C" and the base part of the original file name to "%O".
%o represents the original filename without modifications.
@@ -598,3 +602,4 @@ Id keyword is added to renrot file.
Revision 1.1 2005/10/17 13:39:38 zeus
ChangeLog file is added. Its the very begining.
+
diff --git a/etc/renrot.conf b/etc/renrot.conf
index bf531af..6c62ba4 100644
--- a/etc/renrot.conf
+++ b/etc/renrot.conf
@@ -68,3 +68,7 @@
# Include tags information.
#include = '/etc/renrot/tags.conf'
+
+# Use IPC for execution external command
+#use IPC = No
+
diff --git a/renrot b/renrot
index ece96e6..6a8611d 100755
--- a/renrot
+++ b/renrot
@@ -65,6 +65,7 @@ my %configOptions = (
'mtime' => 1,
'name template' => '%Y%m%d%H%M%S',
'trim' => 1,
+ 'use ipc' => 0,
);
########################################################################################
@@ -100,6 +101,7 @@ my $rotateAngle; # define the angle to rotate on 90, 180 or 270
my $rotateThumbnail; # define the angle to rotate on 90, 180 or 270
my %tagsFromCli; # tags are got from CLI
my $trim; # jpegtran -trim
+my $useIPC; # rotate thumbnail via pipe
my $userComment; # text to put into UserComment tag
my $verbose = 0; # verbosity of output
my $workDir = './'; # we'll work ONLY in current directory
@@ -275,6 +277,7 @@ sub getOptions {
"rotate-thumb=i" => \$rotateThumbnail,
"tag|t=s" => \@tmpTags,
"trim!" => \$trim,
+ "use-ipc!" => \$useIPC,
"user-comment=s" => \$userComment,
"v+" => \$verbose,
"version" => \$showVersion,
@@ -311,6 +314,7 @@ sub getOptions {
dbgmsg (3, " --rotate-thumb: $rotateThumbnail\n") if (defined $rotateThumbnail);
dbgmsg (3, " --tag:\n", join("\n", @tmpTags), "\n") if (scalar(@tmpTags) > 0);
dbgmsg (3, " --trim: ", boolConv($trim), "\n") if (defined $trim);
+ dbgmsg (3, " --use-ipc: ", boolConv($useIPC), "\n") if (defined $useIPC);
dbgmsg (3, " --work-directory: $workDir\n");
dbgmsg (3, " ARGV:\n", join("\n", @ARGV), "\n") if ($fileCount > 0);
@@ -469,6 +473,18 @@ sub parseConfigFile {
#
sub parseConfig {
my $file = shift;
+
+ my $home = $ENV{"HOME"};
+ my @homeRC = ();
+ $home = $ENV{"USERPROFILE"} if (not defined $home);
+
+ if (defined $home and $home ne "") {
+ push (@homeRC, $home . "/" . ".renrotrc");
+ push (@homeRC, $home . "/" . ".renrot/renrot.conf");
+ } else {
+ warnmsg ("User's home environment variable isn't defined or empty!\n");
+ }
+
my @rcFiles = (
"/etc/renrot.rc",
"/etc/renrot/renrot.rc",
@@ -476,8 +492,7 @@ sub parseConfig {
"/usr/local/etc/renrot.rc",
"/usr/local/etc/renrot/renrot.rc",
"/usr/local/etc/renrot/renrot.conf",
- $ENV{"HOME"} . "/" . ".renrotrc",
- $ENV{"HOME"} . "/" . ".renrot/renrot.conf",
+ @homeRC,
);
@rcFiles = ($file) if (defined $file);
@@ -537,6 +552,7 @@ $configOptions{'keywords replace'} = $keywordsReplace if (defined $keywordsRepla
$configOptions{'mtime'} = $mtime if (defined $mtime);
$configOptions{'name template'} = $nameTemplate if (defined $nameTemplate);
$configOptions{'trim'} = $trim if (defined $trim);
+$configOptions{'use ipc'} = $useIPC if (defined $useIPC);
dbgmsg (1, "main(): Show what would have been happened (no real actions).\n") if ($dryRun != 0);
@@ -1166,21 +1182,46 @@ sub rotateImg {
########################################################################################
#
-# rotate thubnail only, where the file was rotated but thumbnail was left untouched
+# thumbWriter() writes binary data as thumbnail to given file
+#
+sub thumbWriter {
+ my $file = shift;
+ my $thethumb = shift;
+
+ # preparing to write thumbnale to the just rotated file
+ my $exifThumbnailed = new Image::ExifTool;
+ $exifThumbnailed->Options(Binary => 1);
+ $exifThumbnailed->SetNewValue("ThumbnailImage", $thethumb, Type => 'ValueConv');
+
+ # writing the changes to the EXIFs
+ exifWriter($exifThumbnailed, $file);
+}
+
+########################################################################################
+#
+# rotateThumbnail() rotates thumbnail only, where the file was rotated but
+# thumbnail was left untouched
#
sub rotateThumbnail {
my $infoObj = shift;
my $file = shift; # file, which thumbnale to transform with jpegtran
my @addon = @_; # the switches for jpegtran to rotate the thumbnail
- if (defined ${$$infoObj{ThumbnailImage}}) {
+ if (not defined ${$$infoObj{ThumbnailImage}}) {
+ warnmsg ("No thumbnail found.\n");
+ return;
+ }
+
+ my $origThumb = ${$$infoObj{ThumbnailImage}};
+
+ if ($configOptions{'use ipc'} == 0) {
# extracting the thumbnail image
my $ThumbnailOriginal = $file . "_thumborig";
unless ( open ( OLDTHUMBNAIL, ">$ThumbnailOriginal" ) ) {
errmsg ("$ThumbnailOriginal wasn't opened!\n");
}
binmode OLDTHUMBNAIL;
- print OLDTHUMBNAIL ${$$infoObj{ThumbnailImage}};
+ print OLDTHUMBNAIL $origThumb;
unless ( close ( OLDTHUMBNAIL ) ) { warnmsg ("$ThumbnailOriginal wasn't closed!\n"); }
# rotating the thumbnail
@@ -1189,24 +1230,47 @@ sub rotateThumbnail {
dbgmsg (3, "rotateThumbnail(): $cmd\n");
system $cmd || ( fatalmsg ("System $cmd failed: $?\n"), die );
- # preparing to write the just rotated thumbnail back to the file
- my $thethumb = getFileData($ThumbnailOriginalRotated);
-
- # preparing to write thumbnale to the just rotated file
- my $exifThumbnailed = new Image::ExifTool;
- $exifThumbnailed->Options(Binary => 1);
-
- $exifThumbnailed->SetNewValue("ThumbnailImage", $thethumb, Type => 'ValueConv');
-
- # writing the changes to the EXIFs
- exifWriter($exifThumbnailed, $file);
+ # write the just rotated thumbnail back to file
+ thumbWriter($file, getFileData($ThumbnailOriginalRotated));
unlink ($ThumbnailOriginalRotated) || ( fatalmsg ("While killing $ThumbnailOriginalRotated.\n"), die );
unlink ($ThumbnailOriginal) || ( fatalmsg ("While killing $ThumbnailOriginal.\n"), die );
+ } else {
+ my $cmd = "jpegtran -copy none @addon";
+ dbgmsg (3, "rotateThumbnail(): $cmd\n");
+
+ # write the just rotated thumbnail back to file
+ thumbWriter($file, piper($origThumb, $cmd));
}
- else {
- warnmsg ("No thumbnail found.\n");
+}
+
+########################################################################################
+#
+# piper() opens two pipes for process object via cmd
+#
+sub piper {
+ use FileHandle;
+ use IPC::Open2;
+
+ my $pipeObj = shift; # the object to be processed via pipe
+ my $pipeCmd = shift; # the pipe command
+
+ local (*READ_FROM_FH, *WRITE_TO_FH); # file handlers
+ unless (open2(\*READ_FROM_FH, \*WRITE_TO_FH, $pipeCmd)) {
+ errmsg ("Unable to create the pipe.\n");
}
+
+ binmode WRITE_TO_FH;
+ print WRITE_TO_FH $pipeObj;
+
+ unless (close(WRITE_TO_FH)) { warnmsg ("WRITE handle wasn't closed!\n"); };
+
+ binmode READ_FROM_FH;
+ my @pipedArr = <READ_FROM_FH>;
+
+ unless (close(READ_FROM_FH)) { warnmsg ("READ handle wasn't closed!\n"); };
+
+ return join("", @pipedArr);
}
########################################################################################
@@ -1261,6 +1325,7 @@ Tag writing options:
Misc options:
--dry-run show what would have been happened
+ --use-ipc (*) thumbnail rotation via pipe, rather than via file
-v number of these options defines debug level
-?, --help display this help and exit
--version output version and exit
@@ -1332,7 +1397,7 @@ sub template2name {
if (defined $infoObj->{"RenRotFileNameOriginal"}) {
$fileNameOriginal = $infoObj->{"RenRotFileNameOriginal"};
# file name starts with letters and ends with digits
- if ($fileNameOriginal =~ m/^[[:alpha:]-_]*(\d+)(\.[^\.]+)?$/) {
+ if ($fileNameOriginal =~ m/^[[:alpha:]\-_]*(\d+)(\.[^\.]+)?$/) {
$fileNameOriginalCounter = $1;
}
if ($fileNameOriginal =~ m/^(.*)\.([^\.]+)$/) {
@@ -1636,6 +1701,10 @@ no tags will be written. Default is to write tags.
show what would have been happened (no real actions)
+=item B<--use-ipc>, B<--no-use-ipc>
+
+thumbnail rotation via pipe, rather than via file. This NOT works under Win32.
+
=item B<-v>
one or more C<-v> sets debug level. From 1 to 4 - internal levels, 5 till 9 -

Return to:

Send suggestions and report system problems to the System administrator.