Image::Magick::Tiler - Slice an image into NxM tiles
This program ships as scripts/synopsis.pl:
#!/usr/bin/env perl use strict; use warnings; use File::Spec; use Image::Magick::Tiler; # ------------------------ my($temp_dir) = '/tmp'; my($tiler) = Image::Magick::Tiler -> new ( input_file => File::Spec -> catdir('t', 'sample.png'), geometry => '3x4+5-6', output_dir => $temp_dir, output_type => 'png', verbose => 2, write => 1, ); my($tiles) = $tiler -> tile; my($count) = $tiler -> count; # Warning: Must go after calling tile(). print "Tiles written: $count. \n"; for my $i (0 .. $#$tiles) { print "Tile: @{[$i + 1]}. File name: $$tiles[$i]{file_name}\n"; }
This slices image.png into 3 tiles horizontally and 4 tiles vertically.
Further, the width of each tile is ( (width of sample.png) / 3) + 5 pixels, and the height of each tile is ( (height of sample.png) / 4) - 6 pixels.
In the geometry option NxM+x+y, the x and y offsets (positive or negative) can be used to change the size of the tiles.
For example, if you specify 2x3, and a vertical line spliting the image goes through an interesting part of the image, you could then try 2x3+50, say, to move the vertical line 50 pixels to the right. This is what I do when printing database schema generated with GraphViz2::DBI.
Aslo, try running: perl scripts/tile.pl -h.
Image::Magick::Tiler is a pure Perl module.
Image::Magick::Tiler
This module is available both as a Unix-style distro (*.tgz) and an ActiveState-style distro (*.ppd). The latter is shipped in a *.zip file.
See http://savage.net.au/Perl-modules.html for details.
See http://savage.net.au/Perl-modules/html/installing-a-module.html for help on unpacking and installing each type of distro.
new(...) returns a Image::Magick::Tiler object.
This is the class contructor.
Parameters:
This parameter as a whole is mandatory.
This parameter is optional.
But, from V 2.00 on, no items within the geometry are optional.
The format of $str is 'NxM+x+y'.
N is the default number of tiles in the horizontal direction.
M is the default number of tiles in the verical direction.
Negative or positive values can be used for x and y. Negative values will probably cause extra tiles to be required to cover the image. That why I used the phrase 'default number of tiles' above.
An example would be '2x3-10-12'.
Default: '2x2+0+0'.
Default: ''.
Default: 'png'.
It takes the values 0, 1 and 2.
If 0, nothing is written. If 1, various statistics are written. If 2, you get stats plus a line about every tile written.
Default: 0.
It takes the values 0 and 1.
A value OF 0 stops tiles being written to disk.
Setting it to 1 causes the tiles to be written to disk using the automatically generated files names as discussed in "tile()".
After calling "tile()", this returns the number of tiles generated.
Here, [ and ] indicate an optional parameter.
Gets or sets the name of the input file.
input_file is a parameter to "new()". See "Constructor and Initialization" for details.
input_file
Gets or sets the geometry to use to cut up the image into tiles.
geometry is a parameter to "new()". See "Constructor and Initialization" for details.
geometry
Returns an arrayref corresponding to the components of the geometry.
Example: '4x5+10-6' is returned as [4, 'x', 5, '+', 10, '-', 6].
Returns a object of type Image::Magick::Tiler.
See above, in the section called 'Constructor and initialization'.
Gets or sets the name of the output directory into which the tiles are written if new() is called as new(write => 1) or if write() is called as write(1).
new()
new(write => 1)
write()
write(1)
output_dir is a parameter to "new()". See "Constructor and Initialization" for details.
output_dir
Gets or sets the type of tile image generated.
$str takes values such as 'png', 'jpg', etc.
output_type is a parameter to "new()". See "Constructor and Initialization" for details.
output_type
Chops up the input image and returns an arrayref of tile details.
Each element of this arrayref is a hashref with these keys:
This is an automatically generated file name.
When the geometry is '2x3+0+0', say, the file names are of the form 1-1.png, 1-2.png, 2-1.png, 2-2.png, 3-1.png and 3-2.png. Clearly, these are just the corresponding matrix subscripts of the tiles.
See "output_type([$str])" to change the output file type.
This is the Image::Magick object for one tile.
Gets or sets the option for how much information is printed to STDOUT.
$int may take the values 0 .. 2.
verbose is a parameter to "new()". See "Constructor and Initialization" for details.
verbose
Gets or sets the option for whether or not the tiles are actaully written to disk.
$Boolean takes the values 0 (do not write tiles) and 1 (write tiles).
write is a parameter to "new()". See "Constructor and Initialization" for details.
write
https://github.com/ronsavage/Image-Magick-Tiler
Email the author, or log a bug on RT:
https://rt.cpan.org/Public/Dist/Display.html?Name=Image::Magick::Tiler.
Image::Magick::Tiler was written by Ron Savage <ron@savage.net.au> in 2005.
Homepage
Australian copyright (c) 2005, Ron Savage. All Programs of mine are 'OSI Certified Open Source Software'; you can redistribute them and/or modify them under the terms of The Perl License, a copy of which is available at: http://www.opensource.org/licenses/index.html
To install Image::Magick::Tiler, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Image::Magick::Tiler
CPAN shell
perl -MCPAN -e shell install Image::Magick::Tiler
For more information on module installation, please visit the detailed CPAN module installation guide.