FromImage.pm

filter: Statementstmt 38.6% 17 / 44 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 55.5% 5 / 9 Podpod 100% 3 / 3 totaltotal 40.3% 25 / 62 CC 6 SCAR 18.7
CC
6
Cov
34%
load_image
12.0
write_file
12.0
load_images
6.0
CRAP 6.5
↑ Summary FromImage/Image.pm »
1 package PDF::FromImage;
2 2 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 our $VERSION = '0.000003';
6  
7 2 ▶use PDF::API2;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Imager;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use PDF::FromImage::Image;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 has images => (
13 is => 'rw',
14 isa => 'ArrayRef',
15 lazy => 1,
16 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
17 2 );
18  
19 =head1 NAME
20  
21 PDF::FromImage - Create PDF slide from images
22  
23 =head1 SYNOPSIS
24
25 use PDF::FromImage;
26
27 my $pdf = PDF::FromImage->new;
28
29 $pdf->load_images(
30 'page1.png',
31 'page2.png',
32 :
33 );
34
35 $pdf->write_file('output.pdf');
36  
37 =head1 DESCRIPTION
38  
39 This module create simple pdf image slide from multiple images.
40  
41 =head1 METHODS
42  
43 =head2 load_image($filename)
44  
45 Load a image file.
46  
47 Supported format are jpeg, tiff, pnm, png, and gif.
48  
49 =cut
50  
51 0 ▶sub load_image {
Subroutine load_image: not called CC=3 SCAR=24.8
Pod documented
52 0 my ($self, $image) = @_;
53  
54 0 my $imager = Imager->new;
55 0 ▶ $imager->read( file => $image )
Branch: 1 branch
BranchTrueFalseTotal
$imager->read("file", $image) or confess($imager->errstr) 0 0 0
56 or confess $imager->errstr;
57  
58 0 my $format = $imager->tags( name => 'i_format' );
59 0 my $supported = grep { $_ eq $format } qw/jpeg tiff pnm png gif/;
60  
61 0 ▶ confess qq{This module doen't support "$format"} unless $supported;
Branch: 1 branch
BranchTrueFalseTotal
unless $supported 0 0 0
62  
63 0 my $image_object = PDF::FromImage::Image->new(
64 src => $image,
65 format => $format,
66 width => $imager->getwidth,
67 height => $imager->getheight,
68 );
69  
70 0 push @{ $self->images }, $image_object;
71 }
72  
73 =head2 load_images(@filenames)
74  
75 Load multiple images.
76  
77 =cut
78  
79 0 ▶sub load_images {
Subroutine load_images: not called CC=2 SCAR=17.9
Pod documented
80 0 my $self = shift;
81 0 $self->load_image($_) for @_;
82 }
83  
84 =head2 write_file($filename)
85  
86 Generate pdf from loaded images, and write it to file.
87  
88 =cut
89  
90 0 ▶sub write_file {
Subroutine write_file: not called CC=3 SCAR=24.8
Pod documented
91 0 my ($self, $filename) = @_;
92 0 ▶ confess 'no image is loaded' unless @{ $self->images };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->images;} 0 0 0
93  
94 0 my $pdf = PDF::API2->new;
95  
96 0 for my $image (@{ $self->images }) {
97 0 my $page = $pdf->page;
98 0 $page->mediabox( $image->width, $image->height );
99  
100 0 my $loader = 'image_' . $image->format;
101 0 my $img = $pdf->$loader($image->src);
102  
103 0 my $gfx = $page->gfx;
104 0 $gfx->image( $img, 0, 0 );
105 }
106  
107 0 $pdf->saveas($filename);
108 0 $pdf->end;
109 }
110  
111 =head1 AUTHOR
112  
113 Daisuke Murase <typester@cpan.org>
114  
115 =head1 COPYRIGHT
116  
117 This program is free software; you can redistribute
118 it and/or modify it under the same terms as Perl itself.
119  
120 The full text of the license can be found in the
121 LICENSE file included with this module.
122  
123 =cut
124  
125 2 1;
↑ Summary FromImage/Image.pm »