view release on metacpan or search on metacpan
Changelog.ini view on Meta::CPAN
[Module]
Name=Image::Magick::Tiler
Changelog.Creator=Module::Metadata::Changes V 2.11
Changelog.Parser=Config::IniFiles V 2.88
[V 2.00]
Date=2016-10-13T13:43:00
Comments= <<EOT
- API change.
- The geometry parameter NxM+x+y now has no optional tile counts (NxM) but allows the
offsets [+-]x[+-]y to be omitted.
- The return parameter has been chopped, so tile() always returns an arrayref.
Revision history for Perl extension Image::Magick::Tiler.
2.00 2016-10-13T13:43:00
- API change.
- The geometry parameter NxM+x+y now has no optional tile counts (NxM) but allows the
offsets [+-]x[+-]y to be omitted.
- The return parameter has been chopped, so tile() always returns an arrayref.
- Replace /usr/bin/perl with /usr/bin/env perl.
- Replace common::sense with use strict and use warnings, to get uninit var warnings.
- Adopt new repo format. This means many small changes.
See http://savage.net.au/Ron/html/My.Workflow.for.Building.Distros.html for notes on the
},
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"runtime" : {
"requires" : {
"File::Basename" : "0",
"File::Spec" : "0",
"Image::Magick" : "0",
"Moo" : "2.002004",
"Types::Standard" : "1.000005",
"strict" : "0",
"warnings" : "0"
}
},
"test" : {
"requires" : {
"File::Temp" : "0",
"Test::Pod" : "1.51",
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: Image-Magick-Tiler
no_index:
directory:
- t
- inc
requires:
File::Basename: '0'
File::Spec: '0'
Image::Magick: '0'
Moo: '2.002004'
Types::Standard: '1.000005'
strict: '0'
warnings: '0'
resources:
bugtracker: https://rt.cpan.org/Public/Dist/Display.html?Name=Image-Magick-Tiler
license: http://dev.perl.org/licenses/
repository: https://github.com/ronsavage/Image-Magick-Tiler.git
version: '2.00'
x_serialization_backend: 'CPAN::Meta::YAML version 0.012'
Makefile.PL view on Meta::CPAN
clean =>
{
FILES => 'blib/* Makefile MANIFEST Image-Magick-Tiler-*'
},
dist =>
{
COMPRESS => 'gzip',
SUFFIX => 'gz'
},
DISTNAME => 'Image-Magick-Tiler',
NAME => 'Image::Magick::Tiler',
PL_FILES => {},
PREREQ_PM =>
{
'File::Basename' => 0,
'File::Spec' => 0,
'Image::Magick' => 0, # Expect Module::Version's mversion to return undef.
'Moo' => 2.002004,
'strict' => 0,
'Types::Standard' => 1.000005,
'warnings' => 0,
},
TEST_REQUIRES =>
{
'File::Temp' => 0,
'Test::Pod' => 1.51,
'Test::Simple' => 1.302052, # For Test::More.
README file for Image::Magick::Tiler.
See also: CHANGES and Changelog.ini.
Warning: WinZip 8.1 and 9.0 both contain an 'accidental' bug which stops
them recognizing POSIX-style directory structures in valid tar files.
You are better off using a reliable tool such as InfoZip:
ftp://ftp.info-zip.org/pub/infozip/
1 Installing from a Unix-like distro
------------------------------------
lib/Image/Magick/Tiler.pm view on Meta::CPAN
package Image::Magick::Tiler;
use strict;
use warnings;
use File::Spec;
use Image::Magick;
use Moo;
use Types::Standard qw/Any ArrayRef Int Str/;
has count =>
(
default => sub {return 0},
is => 'rw',
isa => Int,
lib/Image/Magick/Tiler.pm view on Meta::CPAN
if ($g =~ /^(\d+)(x)(\d)([+-])(\d+)([+-])(\d+)$/)
{
@g = ($1, $2, $3, $4, $5, $6, $7);
$self -> geometry("$g[0]$g[1]$g[2]$g[3]$g[4]$g[5]$g[6]");
$self -> geometry_set([$g[0], $g[1], $g[2], $g[3], $g[4], $g[5], $g[6] ]);
if ($self -> verbose)
{
print "Image::Magick: V @{[$Image::Magick::VERSION || 'undef']}\n";
print "Image::Magick::Tiler: V $Image::Magick::Tiler::VERSION\n";
print "Geometry: $g parsed as NxM+x+y = " . $self -> geometry . "\n";
}
}
else
{
die "Error. Geometry (NxM+x+y = $g) is not in the correct format. \n";
}
} # End of BUILD.
# -----------------------------------------------
sub tile
{
my($self) = @_;
my($image) = Image::Magick -> new();
my($result) = $image -> Read($self -> input_file);
die "Error. Unable to read file $self -> input_file. Image::Magick error: $result\n" if ($result);
my(@g) = @{$self -> geometry_set};
my($param) = {};
$$param{image} = {};
($$param{image}{width}, $$param{image}{height}) = $image -> Get('width', 'height');
$$param{tile} = {};
$$param{tile}{width} = int($$param{image}{width} / $g[0]);
$$param{tile}{height} = int($$param{image}{height} / $g[2]);
if ($self -> verbose)
lib/Image/Magick/Tiler.pm view on Meta::CPAN
$count++;
$output_file_name = "$yg-$xg." . $self -> output_type;
$output_file_name = File::Spec -> catfile($self -> output_dir, $output_file_name) if ($self -> output_dir);
$tile = $image -> Clone();
die "Error. Unable to clone image $output_file_name\n" if (! ref $tile);
$result = $tile -> Crop(x => $x, y => $y, width => $$param{tile}{width}, height => $$param{tile}{height});
die "Error. Unable to crop image $output_file_name. Image::Magick error: $result\n" if ($result);
push @{$output},
{
file_name => $output_file_name,
image => $tile,
};
if ($self -> write)
{
$tile -> Write($output_file_name);
lib/Image/Magick/Tiler.pm view on Meta::CPAN
} # End of tile.
# -----------------------------------------------
1;
__END__
=head1 NAME
Image::Magick::Tiler - Slice an image into NxM tiles
=head1 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;
lib/Image/Magick/Tiler.pm view on Meta::CPAN
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 L<GraphViz2::DBI>.
Aslo, try running: perl scripts/tile.pl -h.
=head1 Description
C<Image::Magick::Tiler> is a pure Perl module.
=head1 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.
=head1 Constructor and initialization
new(...) returns a C<Image::Magick::Tiler> object.
This is the class contructor.
Parameters:
=over 4
=item o input_file => $str
This parameter as a whole is mandatory.
lib/Image/Magick/Tiler.pm view on Meta::CPAN
C<geometry> is a parameter to L</new()>. See L</Constructor and Initialization> for details.
=head2 geometry_set()
Returns an arrayref corresponding to the components of the geometry.
Example: '4x5+10-6' is returned as [4, 'x', 5, '+', 10, '-', 6].
=head2 new()
Returns a object of type C<Image::Magick::Tiler>.
See above, in the section called 'Constructor and initialization'.
=head2 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 C<new()> is called
as C<< new(write => 1) >> or if C<write()> is called as C<write(1)>.
lib/Image/Magick/Tiler.pm view on Meta::CPAN
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 L</output_type([$str])> to change the output file type.
=item o image
This is the Image::Magick object for one tile.
=back
=head2 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.
lib/Image/Magick/Tiler.pm view on Meta::CPAN
C<write> is a parameter to L</new()>. See L</Constructor and Initialization> for details.
=head1 Repository
L<https://github.com/ronsavage/Image-Magick-Tiler>
=head1 Support
Email the author, or log a bug on RT:
L<https://rt.cpan.org/Public/Dist/Display.html?Name=Image::Magick::Tiler>.
=head1 Author
C<Image::Magick::Tiler> was written by Ron Savage I<E<lt>ron@savage.net.auE<gt>> in 2005.
L<Homepage|http://savage.net.au/>
=head1 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
scripts/synopsis.pl view on Meta::CPAN
#!/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;
scripts/tile.pl view on Meta::CPAN
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
use Image::Magick::Tiler;
# -----------------------------------------------
my($option_parser) = Getopt::Long::Parser -> new();
my(%option);
if ($option_parser -> getoptions
(
\%option,
scripts/tile.pl view on Meta::CPAN
'output_dir=s',
'output_type=s',
'verbose=i',
'write=i',
) )
{
pod2usage(1) if ($option{'help'});
# Return 0 for success and 1 for failure.
exit Image::Magick::Tiler -> new(%option) -> tile;
}
else
{
pod2usage(2);
}
__END__
=pod
=head1 NAME
tile.pl - Use Image::Magick::Tiler to convert an image into NxM tiles
=head1 SYNOPSIS
tile.pl [options]
Options:
-help
-input_file anImageFileName
-geometry aString
-output_dir aDirName
#!/usr/bin/env perl
use strict;
use warnings;
use File::Basename; # For fileparse().
use File::Spec;
use File::Temp;
use Image::Magick::Tiler;
use Test::More;
# ------------------------
# The EXLOCK option is for BSD-based systems.
my($temp_dir) = File::Temp -> newdir('temp.XXXX', CLEANUP => 1, EXLOCK => 0, TMPDIR => 1);
my($result) = Image::Magick::Tiler -> new
(
input_file => File::Spec -> catdir('t', 'sample.png'),
geometry => '2x2+6+0',
output_dir => $temp_dir,
output_type => 'png',
verbose => 1,
write => 0,
);
isnt($result, undef, 'new() returned something');
isa_ok($result, 'Image::Magick::Tiler', 'new() returned an object of type Image::Magick::Tiler');
my($ara) = $result -> tile();
isnt($ara, undef, 'tile() returned something');
is($#$ara, 3, 'tile() returned an array ref of 4 elements');
isa_ok($$ara[0]{image}, 'Image::Magick', 'tile() returned an Image::Magick image');
my($name, $path, $suffix) = fileparse($$ara[0]{file_name});
is($name, '1-1.png', 'tile() returned a file name');
done_testing;