Graphics::DZI - DeepZoom Image Pyramid Generation
use Graphics::DZI; my $dzi = Graphics::DZI (image => $image, overlap => $overlap, tilesize => $tilesize, format => $format, ); write_file ('/var/www/xxx.xml', $dzi->descriptor); $dzi->iterate (); # !!! this does only display the tiles on the screen # !!! see Graphics::DZI::Files for a subclass which # !!! actually writes to files
This base package generates tiles from a given image in such a way that they follow the DeepZoom image pyramid scheme. Consequently this image becomes zoomable with tools like Seadragon.
http://en.wikipedia.org/wiki/Deep_Zoom
As this is a base class, you may want to look either at the deepzoom script which operators on the command line, or at one of the subclasses.
The constructor accepts the following fields:
image
The Image::Magick object which is used as canvas.
(since 0.05)
The image can also be a whole stack (Image::Magick allows you to do that). In that case the bottom image is regarded as the one with the highest degree of detail, and that is tiled first (at the higher resolutions). Images up the stack are then taken in turn, until only the top-level image remains. See pop if you want to influence this policy.
pop
scale
Specifies how much the image is stretched in the process.
overlap
Specifies how much the individual tiles overlap.
tilesize
Specifies the quadratic size of each tile.
overlays
An array of Graphics::DZI::Overlay objects which describe how further images are supposed to be composed onto the canvas image.
$tile = $dzi->crop ($scale, $x, $y, $dx, $dy)
Given the dimensions of a tile and a current (not the original) stretch factor this method will return a tile object.
($W, $H) = $dzi->dimensions ('total')
($W, $H) = $dzi->dimensions ('canvas')
This method computes how large (in pixels) the overall image will be. If canvas is passed in, then any overlays are ignored. Otherwise their size (with their squeeze factors) are used to blow up the canvas, so that the overlays fit onto the canvas.
canvas
$dzi->iterate
This method will generate all necessary tiles, invoking the manifest method. You may want to override that one, if you do not want the tiles to be simply displayed on screen :-) Any options you add as parameters will be passed on to manifest.
NOTE: During the process the image will be modified!
This method is only interesting to you if your canvas images is a whole stack, not just a single image. In that case, it will remove the first of the stack (a shift) to make the next in the line visible to the further tiling process. As the tiling starts with the highest resolution, your image stack should be organized that the one with the most details is on the bottom (highest index, pushed last).
This method will do a pop at every half-sizing step and obviously only that long as there is something to shift. If you are not happy with this default policy, you will have to subclass.
$dzi->manifest ($tile, $level, $row, $col)
This method will get one tile as parameter and will simply display the tile on the screen. Subclasses which want to persist the tiles, can use the additional parameters (level, row and column) to create file names.
$string = $dzi->descriptor
This method returns the DZI XML descriptor as string.
See the TODOs file in the distribution.
Robert Barta, <drrho at cpan.org>
<drrho at cpan.org>
Copyright 2010 Robert Barta, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Graphics::DZI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Graphics::DZI
CPAN shell
perl -MCPAN -e shell install Graphics::DZI
For more information on module installation, please visit the detailed CPAN module installation guide.