script/kim_rotate.pl untested

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 2 Podpod n/a totaltotal 0.0% 0 / 58 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl -w
2 # Copyright 2005 Jean-Michel Fayard jmfayard_at_gmail.com
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public
6 # License as published by the Free Software Foundation; either
7 # version 2 of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; see the file COPYING. If not, write to
16 # the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 # Boston, MA 02111-1307, USA.
18  
19 # Changelog:
20 # 17/01/2005 Initial version
21  
22 use strict;
23 use Image::Kimdaba;
24  
25 my $folder=getRootFolder();
26 parseDB( "$folder" );
27 # parse the xml file and create two hashes:
28 # %imageattributes : HASH OF (url of the picture, REF. HASH OF (attribute, value) )
29 # %imageoptions : HASH of (url, REF. HASH OF (optoin, REF. LIST OF value) )
30 my $notest = scalar grep { /--notest/ } @ARGV;
31
32 chdir $folder;
33 my $i=0;
34 for my $url (keys %imageattributes)
35 {
36 $i++;
37 unless( $url =~ m/.jpe?g$/i ) {
38 next;
39 }
40 next unless (-e $url);
41 my $angle=$imageattributes{$url}{"angle"};
42 if ( ($angle eq "180" ) or ( $angle eq "90" ) or ($angle eq "270") ){
43 print "jpegtran -trim -rotate $angle $url ";
44 if ($notest) {
45 my @args=( "jpegtran", "-outfile", "temp.jpg", "-trim", "-rotate" , $angle, $url );
46 my $err = system @args;
47 if ($err != 0)
48 {
49 print "... FAILED\n";
50 } else {
51 $err = rename( "temp.jpg", $url );
52 print ($err!=0?"... FAILED\n":"... OK\n");
53 }
54 } else {
55 print "\n";
56 }
57 }
58 }
59 if ($notest) {
60 symlink "${folder}/index.xml", "${folder}/.index.xml.old" ;
61 print STDERR <<FIN
62 All jpeg pictures rotated. If you already quit Image::Kimdaba,
63 you can manually update your database with following command :
64 \$ perl -pi -e 's/ angle="\\d+/ angle="0/' ${folder}/index.xml
65 FIN
66 ;
67  
68 } else {
69 print STDERR "Now run this script with --notest to really rotate your pictures\n";
70 }