line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Image::Magick::Thumbnail::PDF; |
2
|
2
|
|
|
2
|
|
68200
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
61
|
|
3
|
2
|
|
|
2
|
|
11
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
220
|
|
4
|
|
|
|
|
|
|
require Exporter; |
5
|
2
|
|
|
2
|
|
1602
|
use File::Which; |
|
2
|
|
|
|
|
2095
|
|
|
2
|
|
|
|
|
107
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
12
|
use vars qw{$VERSION @ISA @EXPORT_OK %EXPORT_TAGS}; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
2671
|
|
8
|
|
|
|
|
|
|
$VERSION = sprintf "%d.%02d", q$Revision: 1.13 $ =~ /(\d+)/g; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
@EXPORT_OK = qw(create_thumbnail); |
12
|
|
|
|
|
|
|
%EXPORT_TAGS = ( |
13
|
|
|
|
|
|
|
all => \@EXPORT_OK, |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$Image::Magick::Thumbnail::PDF::DEBUG = 0; |
18
|
15
|
|
|
15
|
0
|
1355
|
sub DEBUG : lvalue { $Image::Magick::Thumbnail::PDF::DEBUG } |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub create_thumbnail { |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# BEGIN GET PARAMS |
23
|
2
|
50
|
|
2
|
0
|
133486
|
print STDERR __PACKAGE__."::create_thumbnail() DEBUG ON\ngetting arguments\n" if DEBUG; |
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
|
|
14
|
my ($abs_pdf,$abs_out,$page_number,$arg,$all); |
26
|
2
|
50
|
|
|
|
7
|
$abs_pdf = shift; $abs_pdf or croak(__PACKAGE__."::create_thumbnail() missing abs pdf argument"); |
|
2
|
|
|
|
|
18
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
|
|
13
|
my $name_of_outfile_in_arguments=0; |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
|
|
12
|
for (@_){ |
32
|
2
|
|
|
|
|
11
|
my $val = $_; |
33
|
2
|
50
|
|
|
|
24
|
print " val [$val]\n" if DEBUG; |
34
|
|
|
|
|
|
|
|
35
|
2
|
50
|
|
|
|
56
|
if (ref $val eq 'HASH'){ |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
0
|
$arg = $val; print STDERR " got args hash ref\n" if DEBUG; |
|
0
|
|
|
|
|
0
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
elsif ($val=~/^\d+$/){ |
39
|
1
|
50
|
|
|
|
2
|
$page_number = $val; print STDERR " got page number $val\n" if DEBUG; |
|
1
|
|
|
|
|
4
|
|
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
elsif ($val eq 'all_pages'){ |
42
|
1
|
50
|
|
|
|
6
|
$all=1; print STDERR " got flag to do all pages\n" if DEBUG; |
|
1
|
|
|
|
|
4
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
elsif ($val=~/[^\/]+\.\w{2,4}$/){ |
45
|
0
|
0
|
|
|
|
0
|
$abs_out = $val; print STDERR " got abs out [$val]\n" if DEBUG; |
|
0
|
|
|
|
|
0
|
|
46
|
0
|
|
|
|
|
0
|
$name_of_outfile_in_arguments=1; |
47
|
|
|
|
|
|
|
} |
48
|
0
|
|
|
|
|
0
|
else { croak(__PACKAGE__."::create_thumbnail() bogus argument [$val]"); } |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
2
|
|
50
|
|
|
37
|
$arg ||={}; |
52
|
2
|
|
50
|
|
|
27
|
$arg->{restriction} ||= 125; |
53
|
2
|
50
|
|
|
|
11
|
unless( defined $arg->{frame} ){ $arg->{frame} = 6; print STDERR " frame defauls to $$arg{frame}\n" if DEBUG; } |
|
2
|
50
|
|
|
|
7
|
|
|
2
|
|
|
|
|
7
|
|
54
|
2
|
50
|
|
|
|
13
|
unless( defined $arg->{normalize}){ $arg->{normalize} = 1; print STDERR " normalize defauls to $$arg{normalize}\n" if DEBUG; } |
|
2
|
50
|
|
|
|
7
|
|
|
2
|
|
|
|
|
6
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# if we are putting a border, we still want the restriction asked for to be obeyed |
58
|
2
|
50
|
|
|
|
31
|
if ($arg->{frame}){ |
59
|
2
|
|
|
|
|
10
|
$arg->{restriction} = ($arg->{restriction} - ($arg->{frame} * 2) ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
100
|
|
|
45
|
$all ||= 0; |
63
|
2
|
|
100
|
|
|
16
|
$page_number ||= 1; |
64
|
|
|
|
|
|
|
|
65
|
2
|
50
|
|
|
|
8
|
unless( $name_of_outfile_in_arguments ){ |
66
|
2
|
|
|
|
|
4
|
$abs_out = $abs_pdf; |
67
|
2
|
|
|
|
|
29
|
$abs_out=~s/\.\w{3,5}$/\.png/; |
68
|
2
|
50
|
|
|
|
16
|
print STDERR " abs out destination path should be: $abs_out\n" if DEBUG; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
2
|
50
|
|
|
|
35
|
$arg->{frame}=~/^\d+$/ or croak(__PACKAGE__."::create_thumbnail() argument 'frame' is not a number"); |
73
|
|
|
|
|
|
|
|
74
|
2
|
50
|
|
|
|
22
|
$arg->{restriction}=~/^\d+$/ or |
75
|
|
|
|
|
|
|
croak(__PACKAGE__."::create_thumbnail() argument 'restriction' is not a number"); |
76
|
|
|
|
|
|
|
|
77
|
2
|
50
|
|
|
|
10
|
if (DEBUG){ |
78
|
2
|
|
|
|
|
219
|
printf STDERR __PACKAGE__."::create_thumbnail() debug.. \n"; |
79
|
2
|
|
|
|
|
229
|
printf STDERR " abs_pdf %s\n page_number %s\n abs_out %s, all? %s\n", $abs_pdf, $page_number, $abs_out, $all; |
80
|
|
|
|
|
|
|
### $arg |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# END GET PARAMS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
2
|
|
|
|
|
1660
|
require Image::Magick::Thumbnail; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my $src = new Image::Magick; |
96
|
0
|
|
|
|
|
|
my $err = $src->Read($abs_pdf);# warn("92 ++++ $err") if $err; |
97
|
0
|
0
|
|
|
|
|
print STDERR "ok read $abs_pdf\n" if DEBUG; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
|
if (!$all){ |
101
|
|
|
|
|
|
|
# not all pages |
102
|
0
|
|
|
|
|
|
my $image = $src->[($page_number-1)]; |
103
|
0
|
0
|
0
|
|
|
|
defined $image or warn("file [$abs_pdf] page number [$page_number] does not exist?") and return; |
104
|
0
|
|
|
|
|
|
my $out = _dopage($image,$abs_out,$page_number,$arg,$name_of_outfile_in_arguments); |
105
|
0
|
|
|
|
|
|
return $out; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
else { |
108
|
0
|
0
|
|
|
|
|
print STDERR "Do all pages\n" if DEBUG; |
109
|
0
|
|
|
|
|
|
my $pagenum = 1; |
110
|
0
|
|
|
|
|
|
my @outs; |
111
|
0
|
|
|
|
|
|
for ( @$src ){ |
112
|
0
|
|
|
|
|
|
my $out = _dopage($_,$abs_out,$pagenum,$arg); |
113
|
0
|
|
|
|
|
|
push @outs, $out; |
114
|
0
|
|
|
|
|
|
$pagenum++; |
115
|
|
|
|
|
|
|
} |
116
|
0
|
|
|
|
|
|
return \@outs; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub _dopage { |
122
|
0
|
|
|
0
|
|
|
my ($image,$abs_out,$pagenum,$arg,$name_of_outfile_in_arguments) = @_; |
123
|
0
|
|
|
|
|
|
$pagenum = sprintf "%03d", $pagenum; |
124
|
0
|
0
|
|
|
|
|
print STDERR " _dopage() $pagenum " if DEBUG; |
125
|
|
|
|
|
|
|
|
126
|
0
|
0
|
|
|
|
|
unless( $name_of_outfile_in_arguments ){ |
127
|
0
|
|
|
|
|
|
$abs_out=~s/(\.\w{3,5})$/-$pagenum$1/; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
0
|
0
|
|
|
|
|
if ( $arg->{normalize} ){ |
131
|
0
|
|
|
|
|
|
my $step = $arg->{restriction} * 2; |
132
|
0
|
|
|
|
|
|
my ($i,$x,$y) = Image::Magick::Thumbnail::create($image,$step); |
133
|
0
|
|
|
|
|
|
$i->Normalize; |
134
|
0
|
|
|
|
|
|
$image = $i; |
135
|
0
|
0
|
|
|
|
|
print STDERR ' (normalized) ' if DEBUG; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
|
if ($arg->{quality}){ |
139
|
0
|
0
|
|
|
|
|
print STDERR " (quality $$arg{quality}) " if DEBUG; |
140
|
0
|
|
|
|
|
|
$image->Set( quality => $arg->{quality} ); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
my($thumb,$x,$y) = Image::Magick::Thumbnail::create($image,$arg->{restriction}); |
145
|
|
|
|
|
|
|
|
146
|
0
|
0
|
|
|
|
|
if ($arg->{frame}){ |
147
|
0
|
|
|
|
|
|
$image->Frame($arg->{frame}.'x'.$arg->{frame}); |
148
|
0
|
0
|
|
|
|
|
print STDERR " (framed $$arg{frame}) " if DEBUG; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
my $err= $thumb->Write($abs_out); #warn("141 +++ $err") if $err; |
152
|
|
|
|
|
|
|
|
153
|
0
|
0
|
|
|
|
|
print STDERR "$abs_out\n" if DEBUG; |
154
|
0
|
|
|
|
|
|
return $abs_out; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
1; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
__END__ |