File Coverage

blib/lib/Graphics/DZI/Files.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package Graphics::DZI::Files;
2              
3 1     1   4219 use warnings;
  1         2  
  1         33  
4 1     1   5 use strict;
  1         2  
  1         30  
5              
6 1     1   469 use Moose;
  0            
  0            
7             extends 'Graphics::DZI';
8              
9             our $log;
10             use Log::Log4perl;
11             BEGIN {
12             $log = Log::Log4perl->get_logger ();
13             }
14              
15             =head1 NAME
16              
17             Graphics::DZI::Files - DeepZoom Image Pyramid Generation, File-based
18              
19             =head1 SYNOPSIS
20              
21             use Graphics::DZI::Files;
22             my $dzi = new Graphics::DZI::Files (image => $image,
23             overlap => 4,
24             tilesize => 256,
25             scale => 2,
26             format => 'png',
27             prefix => 'xxx',
28             path => '/where/ever/');
29             use File::Slurp;
30             write_file ('/where/ever/xxx.xml', $dzi->descriptor);
31             $dzi->iterate ();
32              
33             # since 0.05
34             use Graphics::DZI::Files;
35             my $dzi = new Graphics::DZI::Files (image => $image,
36             dzi => '/tmp/xxx.dzi');
37              
38              
39             =head1 DESCRIPTION
40              
41             This subclass of L<Graphics::DZI> generates tiles and stores them at the specified path location.
42              
43             =head1 INTERFACE
44              
45             =head2 Constructor
46              
47             Additional to the parent class L<Graphics::DZI>, the constructor takes the following fields:
48              
49             =over
50              
51             =item C<format> (default C<png>):
52              
53             An image format (C<png>, C<jpg>, ...). Any format L<Image::Magick> understands will do.
54              
55             =item C<path>: (deprecated from 0.05 onwards, use C<dzi>)
56              
57             A directory name (including trailing C</>) where the tiles are written to. This has to include the
58             C<_files> part required by the DZI format.
59              
60             =item C<prefix>: (deprecated from 0.05 onwards, use C<dzi>)
61              
62             The string to be prefixed the C<_files/> part in the directory name. Usually the name of the image
63             to be converted. No slashes.
64              
65             =item C<dzi> (since 0.05)
66              
67             Alternatively to specifying the path and the prefix separately, you can also provide the full path
68             to the DZI file, say, C</var/www/photo.dzi>. The tiles will be written to
69             C</var/www/photo_files>.
70              
71             =back
72              
73             =cut
74              
75             #has 'format' => (isa => 'Str' , is => 'ro', default => 'png');
76             has 'path' => (isa => 'Str' , is => 'ro');
77             has 'prefix' => (isa => 'Str' , is => 'ro');
78             has 'dzi' => (isa => 'Str' , is => 'ro');
79              
80             =head2 Methods
81              
82             =over
83              
84             =item B<generate>
85              
86             (since 0.05)
87              
88             This method generates everything, the tiles and the XML descriptor. If you have specified a C<dzi>
89             field in the constructor, then you do not need to specify it as parameter. If you have used the
90             C<path>/C<prefix>, then you need to provide the full path.
91              
92             =cut
93              
94             sub generate {
95             my $self = shift;
96              
97             my $dzifile = $self->dzi || shift;
98             use File::Slurp;
99             write_file ($dzifile, $self->descriptor);
100              
101             $self->iterate;
102             }
103              
104             =item B<manifest>
105              
106             This method writes any tile to a file, appropriately named for DZI inclusion.
107              
108             =cut
109              
110             sub manifest {
111             my $self = shift;
112             my $tile = shift;
113             my $level = shift;
114             my $row = shift;
115             my $col = shift;
116              
117             my $path;
118             if ($self->dzi) {
119             $self->dzi =~ m{^(.+)\.(dzi|xml)$};
120             $path = $1 . "_files/$level/";
121             } else {
122             $path = $self->path . "$level/";
123             }
124             use File::Path qw(make_path);
125             make_path ($path);
126              
127             my $filen = $path . (sprintf "%s_%s", $col, $row ) . '.' . $self->format;
128             $log->debug ("saving tile $level $row $col --> $filen");
129             $tile->Write( $filen );
130             }
131              
132             =back
133              
134             =head1 AUTHOR
135              
136             Robert Barta, C<< <drrho at cpan.org> >>
137              
138             =head1 COPYRIGHT & LICENSE
139              
140             Copyright 2010 Robert Barta, all rights reserved.
141              
142             This program is free software; you can redistribute it and/or modify it
143             under the same terms as Perl itself.
144              
145             =cut
146              
147             our $VERSION = '0.02';
148             "against all odds";