NAME

Image::Magick::Tiler - Slice an image into NxM tiles

Synopsis

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.

Description

Image::Magick::Tiler is a pure Perl module.

Distributions

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.

Constructor and initialization

new(...) returns a Image::Magick::Tiler object.

This is the class contructor.

Parameters:

o input_file => $str

This parameter as a whole is mandatory.

o geometry => $str

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'.

o output_dir => $str

This parameter is optional.

Default: ''.

o output_type => $str

This parameter is optional.

Default: 'png'.

o verbose => $int

This parameter is optional.

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.

o write => $Boolean

This parameter is optional.

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()".

Default: 0.

Methods

count()

After calling "tile()", this returns the number of tiles generated.

input_file([$str])

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.

geometry([$str])

Here, [ and ] indicate an optional parameter.

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_set()

Returns an arrayref corresponding to the components of the geometry.

Example: '4x5+10-6' is returned as [4, 'x', 5, '+', 10, '-', 6].

new()

Returns a object of type Image::Magick::Tiler.

See above, in the section called 'Constructor and initialization'.

output_dir([$str])

Here, [ and ] indicate an optional parameter.

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).

output_dir is a parameter to "new()". See "Constructor and Initialization" for details.

output_type([$str])

Here, [ and ] indicate an optional parameter.

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.

tile()

Chops up the input image and returns an arrayref of tile details.

Each element of this arrayref is a hashref with these keys:

o file_name

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.

o image

This is the Image::Magick object for one tile.

verbose([$int])

Here, [ and ] indicate an optional parameter.

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.

write([$Boolean])

Here, [ and ] indicate an optional parameter.

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.

Repository

https://github.com/ronsavage/Image-Magick-Tiler

Support

Email the author, or log a bug on RT:

https://rt.cpan.org/Public/Dist/Display.html?Name=Image::Magick::Tiler.

Author

Image::Magick::Tiler was written by Ron Savage <ron@savage.net.au> in 2005.

Homepage

Copyright

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