Image-Magick-Iterator
view release on metacpan or search on metacpan
Revision history for Perl extension Image::Magick::Iterator.
0.01 Sun May 2 20:16:17 2004
- original version; created by h2xs 1.23 with options
-AXn Image::Magick::Iterator
# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: Image-Magick-Iterator
version: 0.01
version_from: lib/Image/Magick/Iterator.pm
installdirs: site
requires:
Image::Magick: 5.56
Image::PBMlib: 1.05
distribution_type: module
generated_by: ExtUtils::MakeMaker version 6.17
Makefile.PL view on Meta::CPAN
use 5.008001;
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
NAME => 'Image::Magick::Iterator',
VERSION_FROM => 'lib/Image/Magick/Iterator.pm', # finds $VERSION
PREREQ_PM => {
Image::Magick => 5.56,
Image::PBMlib => 1.05,
}, # e.g., Module::Name => 1.1
($] >= 5.005 ? ## Add these new keywords supported since 5.005
(ABSTRACT_FROM => 'lib/Image/Magick/Iterator.pm', # retrieve abstract from module
AUTHOR => 'Allen Day <allenday@ucla.edu>') : ()),
);
ImageMagick-Iterator version 0.01
=============================
These modules add iteration support to Image::Magick. This means that
if you have a stream of concatenated images, you can access each image
in the stream as an independent Image::Magick object.
Iteration functionality is not present in Image::Magick itself as of
version 5.56. Passing a stream of concatenated images would result in
essentially a "stack" of images which would all be manipulated in
parallel by any Image::Magick calls. Calls to Write() either output
an animated series of image (a la animated GIFs), or the first image in
the series.
Image::Magick::Iterator is extensible to support many different
image filetypes. Currently only PPM support is implemented. To iterate
over a PPM stream, the code would look something like:
my $iter = Image::Magick::Iterator->new();
#assume PPM stream is coming from STDIN;
$iter->handle(\*STDIN);
#explicitly set format to PPM, there is no auto-detection built in
$iter->format('PPM');
while(my $image = $iter->next){
print $image->Get('height'),"\n"; #access height attribute of each
#Image::Magick object
}
INSTALLATION
To install this module type the following:
perl Makefile.PL
make
make test
make install
DEPENDENCIES
This module requires these other modules and libraries:
Image::Magick 5.56
Image::PBMlib 1.05
COPYRIGHT AND LICENCE
Copyright (C) 2004 by Allen Day, allenday@ucla.edu
This library is released under GPL, the GNU General Public License
lib/Image/Magick/Iterator.pm view on Meta::CPAN
=head1 NAME
Image::Magick::Iterator - sequentially read Image::Magick object from
a filehandle.
=head1 SYNOPSIS
use strict;
use Image::Magick::Iterator;
my $iter = Image::Magick::Iterator->new();
#assume PPM stream is coming from STDIN;
$iter->handle(\*STDIN);
#explicitly set format to PPM, there is no auto-detection built in
$iter->format('PPM');
while(my $image = $iter->next){
print $image->Get('height'),"\n"; #access height attribute of each
#Image::Magick object
}
=head1 DESCRIPTION
Image::Magick::Iterator adds iteration support to
L<Image::Magick|Image::Magick>. This means that if you have a stream
of concatenated images, you can access each image in the stream as an
independent L<Image::Magick|Image::Magick> object.
Iteration functionality is not present in
L<Image::Magick|Image::Magick> itself as of version 5.56. Passing a
stream of concatenated images would result in essentially a "stack" of
images which would all be manipulated in parallel by any
L<Image::Magick|Image::Magick> calls. Calls to Write() either output
an animated series of image (a la animated GIFs), or the first image
in the series.
Image::Magick::Iterator is extensible to support many different image
filetypes. Currently only PPM support is implemented. See
L</SYNOPSIS|SYOPSIS> for an example.
=head1 SUPPORTED FORMATS
Currently only PPM images can be iterated. It's not difficult to add
new image types though, and I'm receptive to new classes for handling
more formats. To add another format:
1. Have a look at the source of
L<Image::Magick::Iterator::PPM|Image::Magick::Iterator::PPM> to get an
idea of how to write a new format handling class. It is basically a
class with one method, B<read_image>, that when given a filehandle
reference reads an image from it and passes back the raw data.
2. add a mapping to L</_delegate()> that maps the desired value of
L</format()> to your image reading class.
=head1 FEEDBACK
Email the author.
lib/Image/Magick/Iterator.pm view on Meta::CPAN
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a '_'. Methods are
in alphabetical order for the most part.
=cut
# Let the code begin...
package Image::Magick::Iterator;
use strict;
use base qw();
our $VERSION = '0.01';
use File::Temp;
use Image::Magick;
=head2 new()
=over
=item Usage
my $obj = new Image::Magick::Iterator();
=item Function
Builds a new Image::Magick::Iterator object
=item Returns
an instance of Image::Magick::Iterator
=item Arguments
None
=back
=cut
sub new {
lib/Image/Magick/Iterator.pm view on Meta::CPAN
=head2 init()
=over
=item Usage
$obj->init(%arg);
=item Function
Internal method to initialize a new Image::Magick::Iterator object
=item Returns
true on success
=item Arguments
Arguments passed to L</new()>
=back
lib/Image/Magick/Iterator.pm view on Meta::CPAN
$self->{'handle'} = $val if defined($val);
return $self->{'handle'};
}
=head2 next()
=over
=item Usage
$obj->next(); #get next Image::Magick from stream
=item Function
reads an L<Image::Magick|Image::Magick> object from a filehandle.
=item Returns
a L<Image::Magick|Image::Magick> object, or undef if the filehandle is
EOF or contains only a partial image.
=item Arguments
none, read-only
=back
=cut
lib/Image/Magick/Iterator.pm view on Meta::CPAN
eval "require $delegate";
if($@){ die "couldn't load delegate class '$delegate': $@" }
my $raw = $delegate->read_image($self->handle);
return undef unless $raw;
my $tmp = File::Temp->new(UNLINK => 1);
print $tmp $raw;
$image = Image::Magick->new();
close($tmp);
open(IN,"$tmp");
$image->Read(file => \*IN);
close(IN);
return $image;
}
lib/Image/Magick/Iterator.pm view on Meta::CPAN
name of an image format
=back
=cut
sub _delegate {
my ($self,$format) = @_;
my %map = (
PPM => 'Image::Magick::Iterator::PPM',
);
return $map{$format};
}
1;
lib/Image/Magick/Iterator/PPM.pm view on Meta::CPAN
=head1 NAME
Image::Magick::Iterator::PPM - read PPM images
=head1 DESCRIPTION
Image::Magick::Iterator delegates to this class for
low level image byte read()s. Don't use this class
directly.
=head1 FEEDBACK
See L<Image::Magick::Iterator>.
=head1 AUTHOR
Allen Day E<lt>allenday@ucla.eduE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2004 by Allen Day, allenday@ucla.edu
This library is released under GPL, the GNU General Public License
lib/Image/Magick/Iterator/PPM.pm view on Meta::CPAN
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a '_'. Methods are
in alphabetical order for the most part.
=cut
# Let the code begin...
package Image::Magick::Iterator::PPM;
use strict;
use base qw();
use Image::PBMlib;
our $VERSION = '0.01';
=head2 read_image()
=over
=item Usage
t/Image-Magick-Iterator.t view on Meta::CPAN
use strict;
use Data::Dumper;
use Image::Magick;
use Test::More tests => 12;
BEGIN { use_ok('Image::Magick::Iterator') };
ok(open(PPM, 'eg/t.ppm')) or die "couldn't open eg/t.ppm: $!";
ok(my $iter = Image::Magick::Iterator->new());
ok($iter->format('PPM'));
ok($iter->handle(\*PPM));
my $i = 0;
while(my $frame = $iter->next){
is($frame->Get('width') , 320);
is($frame->Get('height'), 240);
$i++;
}
( run in 0.415 second using v1.01-cache-2.11-cpan-beeb90c9504 )