package Imager;
use strict;
-use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS %formats $DEBUG %filters %DSOs $ERRSTR $fontstate %OPCODES $I2P $FORMATGUESS $warn_obsolete);
+use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS %formats $DEBUG %filters %DSOs $ERRSTR %OPCODES $I2P $FORMATGUESS $warn_obsolete);
use IO::File;
use Imager::Color;
i_tt_text
i_tt_bbox
- i_readjpeg_wiol
- i_writejpeg_wiol
-
- i_readtiff_wiol
- i_writetiff_wiol
- i_writetiff_wiol_faxable
-
- i_readpng_wiol
- i_writepng_wiol
-
- i_readgif
- i_readgif_wiol
- i_readgif_callback
- i_writegif
- i_writegifmc
- i_writegif_gen
- i_writegif_callback
-
i_readpnm_wiol
i_writeppm_wiol
newcolour
NC
NF
+ NCF
);
@EXPORT=qw(
newcolor
NF
NC
+ NCF
)],
all => [@EXPORT_OK],
default => [qw(
unload_plugin
)]);
+# registered file readers
+my %readers;
+
+# registered file writers
+my %writers;
+
+# modules we attempted to autoload
+my %attempted_to_load;
+
+# library keys that are image file formats
+my %file_formats = map { $_ => 1 } qw/tiff pnm gif png jpeg raw bmp tga/;
+
+# image pixel combine types
+my @combine_types =
+ qw/none normal multiply dissolve add subtract diff lighten darken
+ hue saturation value color/;
+my %combine_types;
+@combine_types{@combine_types} = 0 .. $#combine_types;
+$combine_types{mult} = $combine_types{multiply};
+$combine_types{'sub'} = $combine_types{subtract};
+$combine_types{sat} = $combine_types{saturation};
+
+# this will be used to store global defaults at some point
+my %defaults;
+
BEGIN {
require Exporter;
- require DynaLoader;
-
- $VERSION = '0.41';
- @ISA = qw(Exporter DynaLoader);
- bootstrap Imager $VERSION;
+ @ISA = qw(Exporter);
+ $VERSION = '0.80';
+ eval {
+ require XSLoader;
+ XSLoader::load(Imager => $VERSION);
+ 1;
+ } or do {
+ require DynaLoader;
+ push @ISA, 'DynaLoader';
+ bootstrap Imager $VERSION;
+ }
}
-BEGIN {
- i_init_fonts(); # Initialize font engines
- Imager::Font::__init();
- for(i_list_formats()) { $formats{$_}++; }
+my %formats_low;
+my %format_classes =
+ (
+ png => "Imager::File::PNG",
+ gif => "Imager::File::GIF",
+ tiff => "Imager::File::TIFF",
+ jpeg => "Imager::File::JPEG",
+ w32 => "Imager::Font::W32",
+ ft2 => "Imager::Font::FT2",
+ );
- if ($formats{'t1'}) {
- i_t1_set_aa(1);
- }
+tie %formats, "Imager::FORMATS", \%formats_low, \%format_classes;
- if (!$formats{'t1'} and !$formats{'tt'}
- && !$formats{'ft2'} && !$formats{'w32'}) {
- $fontstate='no font support';
- }
+BEGIN {
+ for(i_list_formats()) { $formats_low{$_}++; }
%OPCODES=(Add=>[0],Sub=>[1],Mult=>[2],Div=>[3],Parm=>[4],'sin'=>[5],'cos'=>[6],'x'=>[4,0],'y'=>[4,1]);
callsub => sub { my %hsh=@_; i_hardinvert($hsh{image}); }
};
+ $filters{hardinvertall} =
+ {
+ callseq => ['image'],
+ defaults => { },
+ callsub => sub { my %hsh=@_; i_hardinvertall($hsh{image}); }
+ };
+
$filters{autolevels} ={
callseq => ['image','lsat','usat','skew'],
defaults => { lsat=>0.1,usat=>0.1,skew=>0.0 },
callsub => sub { my %hsh=@_; i_radnoise($hsh{image},$hsh{xo},$hsh{yo},$hsh{rscale},$hsh{ascale}); }
};
- $filters{conv} ={
- callseq => ['image', 'coef'],
- defaults => { },
- callsub => sub { my %hsh=@_; i_conv($hsh{image},$hsh{coef}); }
- };
+ $filters{conv} =
+ {
+ callseq => ['image', 'coef'],
+ defaults => { },
+ callsub =>
+ sub {
+ my %hsh=@_;
+ i_conv($hsh{image},$hsh{coef})
+ or die Imager->_error_as_msg() . "\n";
+ }
+ };
- $filters{gradgen} ={
- callseq => ['image', 'xo', 'yo', 'colors', 'dist'],
- defaults => { },
- callsub => sub { my %hsh=@_; i_gradgen($hsh{image}, $hsh{xo}, $hsh{yo}, $hsh{colors}, $hsh{dist}); }
- };
+ $filters{gradgen} =
+ {
+ callseq => ['image', 'xo', 'yo', 'colors', 'dist'],
+ defaults => { dist => 0 },
+ callsub =>
+ sub {
+ my %hsh=@_;
+ my @colors = @{$hsh{colors}};
+ $_ = _color($_)
+ for @colors;
+ i_gradgen($hsh{image}, $hsh{xo}, $hsh{yo}, \@colors, $hsh{dist});
+ }
+ };
- $filters{nearest_color} ={
- callseq => ['image', 'xo', 'yo', 'colors', 'dist'],
- defaults => { },
- callsub => sub { my %hsh=@_; i_nearest_color($hsh{image}, $hsh{xo}, $hsh{yo}, $hsh{colors}, $hsh{dist}); }
- };
+ $filters{nearest_color} =
+ {
+ callseq => ['image', 'xo', 'yo', 'colors', 'dist'],
+ defaults => { },
+ callsub =>
+ sub {
+ my %hsh=@_;
+ # make sure the segments are specified with colors
+ my @colors;
+ for my $color (@{$hsh{colors}}) {
+ my $new_color = _color($color)
+ or die $Imager::ERRSTR."\n";
+ push @colors, $new_color;
+ }
+
+ i_nearest_color($hsh{image}, $hsh{xo}, $hsh{yo}, \@colors,
+ $hsh{dist})
+ or die Imager->_error_as_msg() . "\n";
+ },
+ };
$filters{gaussian} = {
callseq => [ 'image', 'stddev' ],
defaults => { },
cd => 1.0,
cs => 40,
n => 1.3,
- Ia => Imager::Color->new(rgb=>[0,0,0]),
- Il => Imager::Color->new(rgb=>[255,255,255]),
- Is => Imager::Color->new(rgb=>[255,255,255]),
+ Ia => [0,0,0],
+ Il => [255,255,255],
+ Is => [255,255,255],
},
callsub => sub {
my %hsh = @_;
+ for my $cname (qw/Ia Il Is/) {
+ my $old = $hsh{$cname};
+ my $new_color = _color($old)
+ or die $Imager::ERRSTR, "\n";
+ $hsh{$cname} = $new_color;
+ }
i_bumpmap_complex($hsh{image}, $hsh{bump}{IMG}, $hsh{channel},
$hsh{tx}, $hsh{ty}, $hsh{Lx}, $hsh{Ly}, $hsh{Lz},
$hsh{cd}, $hsh{cs}, $hsh{n}, $hsh{Ia}, $hsh{Il},
super_sample => 0, ssample_param => 4,
segments=>[
[ 0, 0.5, 1,
- Imager::Color->new(0,0,0),
- Imager::Color->new(255, 255, 255),
+ [0,0,0],
+ [255, 255, 255],
0, 0,
],
],
callsub =>
sub {
my %hsh = @_;
+
+ # make sure the segments are specified with colors
+ my @segments;
+ for my $segment (@{$hsh{segments}}) {
+ my @new_segment = @$segment;
+
+ $_ = _color($_) or die $Imager::ERRSTR."\n" for @new_segment[3,4];
+ push @segments, \@new_segment;
+ }
+
i_fountain($hsh{image}, $hsh{xa}, $hsh{ya}, $hsh{xb}, $hsh{yb},
$hsh{ftype}, $hsh{repeat}, $hsh{combine}, $hsh{super_sample},
- $hsh{ssample_param}, $hsh{segments});
+ $hsh{ssample_param}, \@segments)
+ or die Imager->_error_as_msg() . "\n";
},
};
$filters{unsharpmask} =
# initlize Imager
# NOTE: this might be moved to an import override later on
-#sub import {
-# my $pack = shift;
-# (look through @_ for special tags, process, and remove them);
-# use Data::Dumper;
-# print Dumper($pack);
-# print Dumper(@_);
-#}
+sub import {
+ my $i = 1;
+ while ($i < @_) {
+ if ($_[$i] eq '-log-stderr') {
+ init_log(undef, 4);
+ splice(@_, $i, 1);
+ }
+ else {
+ ++$i;
+ }
+ }
+ goto &Exporter::import;
+}
sub init_log {
- m_init_log($_[0],$_[1]);
- log_entry("Imager $VERSION starting\n", 1);
+ i_init_log($_[0],$_[1]);
+ i_log_entry("Imager $VERSION starting\n", 1);
}
$result = Imager::Color->new(%$arg);
}
elsif ($copy =~ /^ARRAY\(/) {
- if (grep $_ > 1, @$arg) {
- $result = Imager::Color->new(@$arg);
- }
- else {
- $result = Imager::Color::Float->new(@$arg);
- }
+ $result = Imager::Color->new(@$arg);
}
else {
$Imager::ERRSTR = "Not a color";
return $result;
}
+sub _combine {
+ my ($self, $combine, $default) = @_;
+
+ if (!defined $combine && ref $self) {
+ $combine = $self->{combine};
+ }
+ defined $combine or $combine = $defaults{combine};
+ defined $combine or $combine = $default;
+
+ if (exists $combine_types{$combine}) {
+ $combine = $combine_types{$combine};
+ }
+
+ return $combine;
+}
+
+sub _valid_image {
+ my ($self) = @_;
+
+ $self->{IMG} and return 1;
+
+ $self->_set_error('empty input image');
+
+ return;
+}
+
+# returns first defined parameter
+sub _first {
+ for (@_) {
+ return $_ if defined $_;
+ }
+ return undef;
+}
#
# Methods to be called on objects.
$self->{IMG}=undef; # Just to indicate what exists
$self->{ERRSTR}=undef; #
$self->{DEBUG}=$DEBUG;
- $self->{DEBUG} && print "Initialized Imager\n";
- if ($hsh{xsize} && $hsh{ysize}) { $self->img_set(%hsh); }
+ $self->{DEBUG} and print "Initialized Imager\n";
+ if (defined $hsh{xsize} || defined $hsh{ysize}) {
+ unless ($self->img_set(%hsh)) {
+ $Imager::ERRSTR = $self->{ERRSTR};
+ return;
+ }
+ }
+ elsif (defined $hsh{file} ||
+ defined $hsh{fh} ||
+ defined $hsh{fd} ||
+ defined $hsh{callback} ||
+ defined $hsh{readcb} ||
+ defined $hsh{data}) {
+ # allow $img = Imager->new(file => $filename)
+ my %extras;
+
+ # type is already used as a parameter to new(), rename it for the
+ # call to read()
+ if ($hsh{filetype}) {
+ $extras{type} = $hsh{filetype};
+ }
+ unless ($self->read(%hsh, %extras)) {
+ $Imager::ERRSTR = $self->{ERRSTR};
+ return;
+ }
+ }
+
return $self;
}
my $self = shift;
unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; }
+ unless (defined wantarray) {
+ my @caller = caller;
+ warn "copy() called in void context - copy() returns the copied image at $caller[1] line $caller[2]\n";
+ return;
+ }
+
my $newcopy=Imager->new();
- $newcopy->{IMG}=i_img_new();
- i_copy($newcopy->{IMG},$self->{IMG});
+ $newcopy->{IMG} = i_copy($self->{IMG});
return $newcopy;
}
sub paste {
my $self = shift;
- unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; }
- my %input=(left=>0, top=>0, @_);
- unless($input{img}) {
- $self->{ERRSTR}="no source image";
+
+ unless ($self->{IMG}) {
+ $self->_set_error('empty input image');
+ return;
+ }
+ my %input=(left=>0, top=>0, src_minx => 0, src_miny => 0, @_);
+ my $src = $input{img} || $input{src};
+ unless($src) {
+ $self->_set_error("no source image");
return;
}
$input{left}=0 if $input{left} <= 0;
$input{top}=0 if $input{top} <= 0;
- my $src=$input{img};
+
my($r,$b)=i_img_info($src->{IMG});
+ my ($src_left, $src_top) = @input{qw/src_minx src_miny/};
+ my ($src_right, $src_bottom);
+ if ($input{src_coords}) {
+ ($src_left, $src_top, $src_right, $src_bottom) = @{$input{src_coords}}
+ }
+ else {
+ if (defined $input{src_maxx}) {
+ $src_right = $input{src_maxx};
+ }
+ elsif (defined $input{width}) {
+ if ($input{width} <= 0) {
+ $self->_set_error("paste: width must me positive");
+ return;
+ }
+ $src_right = $src_left + $input{width};
+ }
+ else {
+ $src_right = $r;
+ }
+ if (defined $input{src_maxy}) {
+ $src_bottom = $input{src_maxy};
+ }
+ elsif (defined $input{height}) {
+ if ($input{height} < 0) {
+ $self->_set_error("paste: height must be positive");
+ return;
+ }
+ $src_bottom = $src_top + $input{height};
+ }
+ else {
+ $src_bottom = $b;
+ }
+ }
+
+ $src_right > $r and $src_right = $r;
+ $src_bottom > $b and $src_bottom = $b;
+
+ if ($src_right <= $src_left
+ || $src_bottom < $src_top) {
+ $self->_set_error("nothing to paste");
+ return;
+ }
i_copyto($self->{IMG}, $src->{IMG},
- 0,0, $r, $b, $input{left}, $input{top});
+ $src_left, $src_top, $src_right, $src_bottom,
+ $input{left}, $input{top});
+
return $self; # What should go here??
}
sub crop {
my $self=shift;
unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; }
- my %hsh=(left=>0,right=>0,top=>0,bottom=>0,@_);
+
+ unless (defined wantarray) {
+ my @caller = caller;
+ warn "crop() called in void context - crop() returns the cropped image at $caller[1] line $caller[2]\n";
+ return;
+ }
- my ($w,$h,$l,$r,$b,$t)=($self->getwidth(),$self->getheight(),
- @hsh{qw(left right bottom top)});
- $l=0 if not defined $l;
- $t=0 if not defined $t;
+ my %hsh=@_;
- $r||=$l+delete $hsh{'width'} if defined $l and exists $hsh{'width'};
- $b||=$t+delete $hsh{'height'} if defined $t and exists $hsh{'height'};
- $l||=$r-delete $hsh{'width'} if defined $r and exists $hsh{'width'};
- $t||=$b-delete $hsh{'height'} if defined $b and exists $hsh{'height'};
+ my ($w, $h, $l, $r, $b, $t) =
+ @hsh{qw(width height left right bottom top)};
- $r=$self->getwidth if not defined $r;
- $b=$self->getheight if not defined $b;
+ # work through the various possibilities
+ if (defined $l) {
+ if (defined $w) {
+ $r = $l + $w;
+ }
+ elsif (!defined $r) {
+ $r = $self->getwidth;
+ }
+ }
+ elsif (defined $r) {
+ if (defined $w) {
+ $l = $r - $w;
+ }
+ else {
+ $l = 0;
+ }
+ }
+ elsif (defined $w) {
+ $l = int(0.5+($self->getwidth()-$w)/2);
+ $r = $l + $w;
+ }
+ else {
+ $l = 0;
+ $r = $self->getwidth;
+ }
+ if (defined $t) {
+ if (defined $h) {
+ $b = $t + $h;
+ }
+ elsif (!defined $b) {
+ $b = $self->getheight;
+ }
+ }
+ elsif (defined $b) {
+ if (defined $h) {
+ $t = $b - $h;
+ }
+ else {
+ $t = 0;
+ }
+ }
+ elsif (defined $h) {
+ $t=int(0.5+($self->getheight()-$h)/2);
+ $b=$t+$h;
+ }
+ else {
+ $t = 0;
+ $b = $self->getheight;
+ }
($l,$r)=($r,$l) if $l>$r;
($t,$b)=($b,$t) if $t>$b;
- if ($hsh{'width'}) {
- $l=int(0.5+($w-$hsh{'width'})/2);
- $r=$l+$hsh{'width'};
- } else {
- $hsh{'width'}=$r-$l;
+ $l < 0 and $l = 0;
+ $r > $self->getwidth and $r = $self->getwidth;
+ $t < 0 and $t = 0;
+ $b > $self->getheight and $b = $self->getheight;
+
+ if ($l == $r || $t == $b) {
+ $self->_set_error("resulting image would have no content");
+ return;
}
- if ($hsh{'height'}) {
- $b=int(0.5+($h-$hsh{'height'})/2);
- $t=$h+$hsh{'height'};
- } else {
- $hsh{'height'}=$b-$t;
+ if( $r < $l or $b < $t ) {
+ $self->_set_error("attempting to crop outside of the image");
+ return;
}
-
-# print "l=$l, r=$r, h=$hsh{'width'}\n";
-# print "t=$t, b=$b, w=$hsh{'height'}\n";
-
- my $dst=Imager->new(xsize=>$hsh{'width'}, ysize=>$hsh{'height'}, channels=>$self->getchannels());
+ my $dst = $self->_sametype(xsize=>$r-$l, ysize=>$b-$t);
i_copyto($dst->{IMG},$self->{IMG},$l,$t,$r,$b,0,0);
return $dst;
}
+sub _sametype {
+ my ($self, %opts) = @_;
+
+ $self->{IMG} or return $self->_set_error("Not a valid image");
+
+ my $x = $opts{xsize} || $self->getwidth;
+ my $y = $opts{ysize} || $self->getheight;
+ my $channels = $opts{channels} || $self->getchannels;
+
+ my $out = Imager->new;
+ if ($channels == $self->getchannels) {
+ $out->{IMG} = i_sametype($self->{IMG}, $x, $y);
+ }
+ else {
+ $out->{IMG} = i_sametype_chans($self->{IMG}, $x, $y, $channels);
+ }
+ unless ($out->{IMG}) {
+ $self->{ERRSTR} = $self->_error_as_msg;
+ return;
+ }
+
+ return $out;
+}
+
# Sets an image to a certain size and channel number
# if there was previously data in the image it is discarded
$self->{IMG}=Imager::ImgRaw::new($hsh{'xsize'}, $hsh{'ysize'},
$hsh{'channels'});
}
+
+ unless ($self->{IMG}) {
+ $self->{ERRSTR} = Imager->_error_as_msg();
+ return;
+ }
+
+ $self;
}
# created a masked version of the current image
$result->{IMG} = i_img_masked_new($self->{IMG}, $mask, $opts{left},
$opts{top}, $opts{right} - $opts{left},
$opts{bottom} - $opts{top});
+ unless ($result->{IMG}) {
+ $self->_set_error(Imager->_error_as_msg);
+ return;
+ }
+
# keep references to the mask and base images so they don't
# disappear on us
$result->{DEPENDS} = [ $self->{IMG}, $mask ];
- $result;
+ return $result;
}
# convert an RGB image into a paletted image
$opts = shift;
}
+ unless (defined wantarray) {
+ my @caller = caller;
+ warn "to_paletted() called in void context - to_paletted() returns the converted image at $caller[1] line $caller[2]\n";
+ return;
+ }
+
my $result = Imager->new;
$result->{IMG} = i_img_to_pal($self->{IMG}, $opts);
#print "Type ", i_img_type($result->{IMG}), "\n";
- $result->{IMG} or undef $result;
-
- return $result;
+ if ($result->{IMG}) {
+ return $result;
+ }
+ else {
+ $self->{ERRSTR} = $self->_error_as_msg;
+ return;
+ }
}
# convert a paletted (or any image) to an 8-bit/channel RGB images
my $self = shift;
my $result;
+ unless (defined wantarray) {
+ my @caller = caller;
+ warn "to_rgb8() called in void context - to_rgb8() returns the converted image at $caller[1] line $caller[2]\n";
+ return;
+ }
+
if ($self->{IMG}) {
$result = Imager->new;
$result->{IMG} = i_img_to_rgb($self->{IMG})
return $result;
}
+# convert a paletted (or any image) to an 8-bit/channel RGB images
+sub to_rgb16 {
+ my $self = shift;
+ my $result;
+
+ unless (defined wantarray) {
+ my @caller = caller;
+ warn "to_rgb16() called in void context - to_rgb8() returns the converted image at $caller[1] line $caller[2]\n";
+ return;
+ }
+
+ if ($self->{IMG}) {
+ $result = Imager->new;
+ $result->{IMG} = i_img_to_rgb16($self->{IMG})
+ or undef $result;
+ }
+
+ return $result;
+}
+
sub addcolors {
my $self = shift;
my %opts = (colors=>[], @_);
- @{$opts{colors}} or return undef;
+ unless ($self->{IMG}) {
+ $self->_set_error("empty input image");
+ return;
+ }
+
+ my @colors = @{$opts{colors}}
+ or return undef;
+
+ for my $color (@colors) {
+ $color = _color($color);
+ unless ($color) {
+ $self->_set_error($Imager::ERRSTR);
+ return;
+ }
+ }
- $self->{IMG} and i_addcolors($self->{IMG}, @{$opts{colors}});
+ return i_addcolors($self->{IMG}, @colors);
}
sub setcolors {
my $self = shift;
my %opts = (start=>0, colors=>[], @_);
- @{$opts{colors}} or return undef;
- $self->{IMG} and i_setcolors($self->{IMG}, $opts{start}, @{$opts{colors}});
+ unless ($self->{IMG}) {
+ $self->_set_error("empty input image");
+ return;
+ }
+
+ my @colors = @{$opts{colors}}
+ or return undef;
+
+ for my $color (@colors) {
+ $color = _color($color);
+ unless ($color) {
+ $self->_set_error($Imager::ERRSTR);
+ return;
+ }
+ }
+
+ return i_setcolors($self->{IMG}, $opts{start}, @colors);
}
sub getcolors {
$self->{IMG} and i_img_virtual($self->{IMG});
}
+sub is_bilevel {
+ my ($self) = @_;
+
+ $self->{IMG} or return;
+
+ return i_img_is_monochrome($self->{IMG});
+}
+
sub tags {
my ($self, %opts) = @_;
}
}
-my @needseekcb = qw/tiff/;
-my %needseekcb = map { $_, $_ } @needseekcb;
-
sub _get_reader_io {
- my ($self, $input, $type) = @_;
+ my ($self, $input) = @_;
- if ($input->{fd}) {
+ if ($input->{io}) {
+ return $input->{io}, undef;
+ }
+ elsif ($input->{fd}) {
return io_new_fd($input->{fd});
}
elsif ($input->{fh}) {
my $fd = fileno($input->{fh});
- unless ($fd) {
+ unless (defined $fd) {
$self->_set_error("Handle in fh option not opened");
return;
}
return io_new_buffer($input->{data});
}
elsif ($input->{callback} || $input->{readcb}) {
- if ($needseekcb{$type} && !$input->{seekcb}) {
- $self->_set_error("Format $type needs a seekcb parameter");
+ if (!$input->{seekcb}) {
+ $self->_set_error("Need a seekcb parameter");
}
if ($input->{maxbuffer}) {
return io_new_cb($input->{writecb},
sub _get_writer_io {
my ($self, $input, $type) = @_;
- if ($input->{fd}) {
+ if ($input->{io}) {
+ return $input->{io};
+ }
+ elsif ($input->{fd}) {
return io_new_fd($input->{fd});
}
elsif ($input->{fh}) {
my $fd = fileno($input->{fh});
- unless ($fd) {
+ unless (defined $fd) {
$self->_set_error("Handle in fh option not opened");
return;
}
undef($self->{IMG});
}
- # FIXME: Find the format here if not specified
- # yes the code isn't here yet - next week maybe?
- # Next week? Are you high or something? That comment
- # has been there for half a year dude.
- # Look, i just work here, ok?
+ my ($IO, $fh) = $self->_get_reader_io(\%input) or return;
- if (!$input{'type'} and $input{file}) {
- $input{'type'}=$FORMATGUESS->($input{file});
+ unless ($input{'type'}) {
+ $input{'type'} = i_test_format_probe($IO, -1);
}
+
unless ($input{'type'}) {
- $self->_set_error('type parameter missing and not possible to guess from extension');
+ $self->_set_error('type parameter missing and not possible to guess from extension');
return undef;
}
- if (!$formats{$input{'type'}}) {
- $self->{ERRSTR}='format not supported'; return undef;
- }
- my %iolready=(jpeg=>1, png=>1, tiff=>1, pnm=>1, raw=>1, bmp=>1, tga=>1, rgb=>1, gif=>1);
+ _reader_autoload($input{type});
- if ($iolready{$input{'type'}}) {
- # Setup data source
- my ($IO, $fh) = $self->_get_reader_io(\%input, $input{'type'})
- or return;
+ if ($readers{$input{type}} && $readers{$input{type}}{single}) {
+ return $readers{$input{type}}{single}->($self, $IO, %input);
+ }
- if ( $input{'type'} eq 'jpeg' ) {
- ($self->{IMG},$self->{IPTCRAW})=i_readjpeg_wiol( $IO );
- if ( !defined($self->{IMG}) ) {
- $self->{ERRSTR}='unable to read jpeg image'; return undef;
- }
- $self->{DEBUG} && print "loading a jpeg file\n";
- return $self;
- }
+ unless ($formats_low{$input{'type'}}) {
+ my $read_types = join ', ', sort Imager->read_types();
+ $self->_set_error("format '$input{'type'}' not supported - formats $read_types available for reading");
+ return;
+ }
- if ( $input{'type'} eq 'tiff' ) {
- $self->{IMG}=i_readtiff_wiol( $IO, -1 ); # Fixme, check if that length parameter is ever needed
- if ( !defined($self->{IMG}) ) {
- $self->{ERRSTR}=$self->_error_as_msg(); return undef;
- }
- $self->{DEBUG} && print "loading a tiff file\n";
- return $self;
- }
+ my $allow_incomplete = $input{allow_incomplete};
+ defined $allow_incomplete or $allow_incomplete = 0;
- if ( $input{'type'} eq 'pnm' ) {
- $self->{IMG}=i_readpnm_wiol( $IO, -1 ); # Fixme, check if that length parameter is ever needed
- if ( !defined($self->{IMG}) ) {
- $self->{ERRSTR}='unable to read pnm image: '._error_as_msg(); return undef;
- }
- $self->{DEBUG} && print "loading a pnm file\n";
- return $self;
+ if ( $input{'type'} eq 'pnm' ) {
+ $self->{IMG}=i_readpnm_wiol( $IO, $allow_incomplete );
+ if ( !defined($self->{IMG}) ) {
+ $self->{ERRSTR}='unable to read pnm image: '._error_as_msg();
+ return undef;
}
+ $self->{DEBUG} && print "loading a pnm file\n";
+ return $self;
+ }
- if ( $input{'type'} eq 'png' ) {
- $self->{IMG}=i_readpng_wiol( $IO, -1 ); # Fixme, check if that length parameter is ever needed
- if ( !defined($self->{IMG}) ) {
- $self->{ERRSTR}='unable to read png image';
- return undef;
- }
- $self->{DEBUG} && print "loading a png file\n";
+ if ( $input{'type'} eq 'bmp' ) {
+ $self->{IMG}=i_readbmp_wiol( $IO, $allow_incomplete );
+ if ( !defined($self->{IMG}) ) {
+ $self->{ERRSTR}=$self->_error_as_msg();
+ return undef;
}
+ $self->{DEBUG} && print "loading a bmp file\n";
+ }
- if ( $input{'type'} eq 'bmp' ) {
- $self->{IMG}=i_readbmp_wiol( $IO );
- if ( !defined($self->{IMG}) ) {
- $self->{ERRSTR}=$self->_error_as_msg();
- return undef;
- }
- $self->{DEBUG} && print "loading a bmp file\n";
+ if ( $input{'type'} eq 'gif' ) {
+ if ($input{colors} && !ref($input{colors})) {
+ # must be a reference to a scalar that accepts the colour map
+ $self->{ERRSTR} = "option 'colors' must be a scalar reference";
+ return undef;
}
-
- if ( $input{'type'} eq 'gif' ) {
- if ($input{colors} && !ref($input{colors})) {
- # must be a reference to a scalar that accepts the colour map
- $self->{ERRSTR} = "option 'colors' must be a scalar reference";
- return undef;
- }
+ if ($input{'gif_consolidate'}) {
if ($input{colors}) {
- my $colors;
- ($self->{IMG}, $colors) =i_readgif_wiol( $IO );
- if ($colors) {
- ${ $input{colors} } = [ map { NC(@$_) } @$colors ];
- }
+ my $colors;
+ ($self->{IMG}, $colors) =i_readgif_wiol( $IO );
+ if ($colors) {
+ ${ $input{colors} } = [ map { NC(@$_) } @$colors ];
+ }
}
else {
- $self->{IMG} =i_readgif_wiol( $IO );
- }
- if ( !defined($self->{IMG}) ) {
- $self->{ERRSTR}=$self->_error_as_msg();
- return undef;
+ $self->{IMG} =i_readgif_wiol( $IO );
}
- $self->{DEBUG} && print "loading a gif file\n";
}
-
- if ( $input{'type'} eq 'tga' ) {
- $self->{IMG}=i_readtga_wiol( $IO, -1 ); # Fixme, check if that length parameter is ever needed
- if ( !defined($self->{IMG}) ) {
- $self->{ERRSTR}=$self->_error_as_msg();
- return undef;
+ else {
+ my $page = $input{'page'};
+ defined $page or $page = 0;
+ $self->{IMG} = i_readgif_single_wiol( $IO, $page );
+ if ($self->{IMG} && $input{colors}) {
+ ${ $input{colors} } =
+ [ i_getcolors($self->{IMG}, 0, i_colorcount($self->{IMG})) ];
}
- $self->{DEBUG} && print "loading a tga file\n";
}
- if ( $input{'type'} eq 'rgb' ) {
- $self->{IMG}=i_readrgb_wiol( $IO, -1 ); # Fixme, check if that length parameter is ever needed
- if ( !defined($self->{IMG}) ) {
- $self->{ERRSTR}=$self->_error_as_msg();
- return undef;
- }
- $self->{DEBUG} && print "loading a tga file\n";
+ if ( !defined($self->{IMG}) ) {
+ $self->{ERRSTR}=$self->_error_as_msg();
+ return undef;
}
+ $self->{DEBUG} && print "loading a gif file\n";
+ }
-
- if ( $input{'type'} eq 'raw' ) {
- my %params=(datachannels=>3,storechannels=>3,interleave=>1,%input);
-
- if ( !($params{xsize} && $params{ysize}) ) {
- $self->{ERRSTR}='missing xsize or ysize parameter for raw';
- return undef;
- }
-
- $self->{IMG} = i_readraw_wiol( $IO,
- $params{xsize},
- $params{ysize},
- $params{datachannels},
- $params{storechannels},
- $params{interleave});
- if ( !defined($self->{IMG}) ) {
- $self->{ERRSTR}='unable to read raw image';
- return undef;
- }
- $self->{DEBUG} && print "loading a raw file\n";
+ if ( $input{'type'} eq 'tga' ) {
+ $self->{IMG}=i_readtga_wiol( $IO, -1 ); # Fixme, check if that length parameter is ever needed
+ if ( !defined($self->{IMG}) ) {
+ $self->{ERRSTR}=$self->_error_as_msg();
+ return undef;
}
+ $self->{DEBUG} && print "loading a tga file\n";
+ }
- } else {
-
- # Old code for reference while changing the new stuff
-
- if (!$input{'type'} and $input{file}) {
- $input{'type'}=$FORMATGUESS->($input{file});
+ if ( $input{'type'} eq 'raw' ) {
+ unless ( $input{xsize} && $input{ysize} ) {
+ $self->_set_error('missing xsize or ysize parameter for raw');
+ return undef;
}
- if (!$input{'type'}) {
- $self->{ERRSTR}='type parameter missing and not possible to guess from extension'; return undef;
+ my $interleave = _first($input{raw_interleave}, $input{interleave});
+ unless (defined $interleave) {
+ my @caller = caller;
+ warn "read(type => 'raw') $caller[2] line $caller[1]: supply interleave or raw_interleave for future compatibility\n";
+ $interleave = 1;
}
-
- if (!$formats{$input{'type'}}) {
- $self->{ERRSTR}='format not supported';
+ my $data_ch = _first($input{raw_datachannels}, $input{datachannels}, 3);
+ my $store_ch = _first($input{raw_storechannels}, $input{storechannels}, 3);
+
+ $self->{IMG} = i_readraw_wiol( $IO,
+ $input{xsize},
+ $input{ysize},
+ $data_ch,
+ $store_ch,
+ $interleave);
+ if ( !defined($self->{IMG}) ) {
+ $self->{ERRSTR}=$self->_error_as_msg();
return undef;
}
+ $self->{DEBUG} && print "loading a raw file\n";
+ }
- my ($fh, $fd);
- if ($input{file}) {
- $fh = new IO::File($input{file},"r");
- if (!defined $fh) {
- $self->{ERRSTR}='Could not open file';
- return undef;
+ return $self;
+}
+
+sub register_reader {
+ my ($class, %opts) = @_;
+
+ defined $opts{type}
+ or die "register_reader called with no type parameter\n";
+
+ my $type = $opts{type};
+
+ defined $opts{single} || defined $opts{multiple}
+ or die "register_reader called with no single or multiple parameter\n";
+
+ $readers{$type} = { };
+ if ($opts{single}) {
+ $readers{$type}{single} = $opts{single};
+ }
+ if ($opts{multiple}) {
+ $readers{$type}{multiple} = $opts{multiple};
+ }
+
+ return 1;
+}
+
+sub register_writer {
+ my ($class, %opts) = @_;
+
+ defined $opts{type}
+ or die "register_writer called with no type parameter\n";
+
+ my $type = $opts{type};
+
+ defined $opts{single} || defined $opts{multiple}
+ or die "register_writer called with no single or multiple parameter\n";
+
+ $writers{$type} = { };
+ if ($opts{single}) {
+ $writers{$type}{single} = $opts{single};
+ }
+ if ($opts{multiple}) {
+ $writers{$type}{multiple} = $opts{multiple};
+ }
+
+ return 1;
+}
+
+sub read_types {
+ my %types =
+ (
+ map { $_ => 1 }
+ keys %readers,
+ grep($file_formats{$_}, keys %formats),
+ qw(ico sgi), # formats not handled directly, but supplied with Imager
+ );
+
+ return keys %types;
+}
+
+sub write_types {
+ my %types =
+ (
+ map { $_ => 1 }
+ keys %writers,
+ grep($file_formats{$_}, keys %formats),
+ qw(ico sgi), # formats not handled directly, but supplied with Imager
+ );
+
+ return keys %types;
+}
+
+# probes for an Imager::File::whatever module
+sub _reader_autoload {
+ my $type = shift;
+
+ return if $formats_low{$type} || $readers{$type};
+
+ return unless $type =~ /^\w+$/;
+
+ my $file = "Imager/File/\U$type\E.pm";
+
+ unless ($attempted_to_load{$file}) {
+ eval {
+ ++$attempted_to_load{$file};
+ require $file;
+ };
+ if ($@) {
+ # try to get a reader specific module
+ my $file = "Imager/File/\U$type\EReader.pm";
+ unless ($attempted_to_load{$file}) {
+ eval {
+ ++$attempted_to_load{$file};
+ require $file;
+ };
}
- binmode($fh);
- $fd = $fh->fileno();
}
+ }
+}
- if ($input{fd}) {
- $fd=$input{fd};
- }
+# probes for an Imager::File::whatever module
+sub _writer_autoload {
+ my $type = shift;
- if ( $input{'type'} eq 'gif' ) {
- my $colors;
- if ($input{colors} && !ref($input{colors})) {
- # must be a reference to a scalar that accepts the colour map
- $self->{ERRSTR} = "option 'colors' must be a scalar reference";
- return undef;
- }
- if (exists $input{data}) {
- if ($input{colors}) {
- ($self->{IMG}, $colors) = i_readgif_scalar($input{data});
- } else {
- $self->{IMG}=i_readgif_scalar($input{data});
- }
- } else {
- if ($input{colors}) {
- ($self->{IMG}, $colors) = i_readgif( $fd );
- } else {
- $self->{IMG} = i_readgif( $fd )
- }
- }
- if ($colors) {
- # we may or may not change i_readgif to return blessed objects...
- ${ $input{colors} } = [ map { NC(@$_) } @$colors ];
- }
- if ( !defined($self->{IMG}) ) {
- $self->{ERRSTR}= 'reading GIF:'._error_as_msg();
- return undef;
+ return if $formats_low{$type} || $readers{$type};
+
+ return unless $type =~ /^\w+$/;
+
+ my $file = "Imager/File/\U$type\E.pm";
+
+ unless ($attempted_to_load{$file}) {
+ eval {
+ ++$attempted_to_load{$file};
+ require $file;
+ };
+ if ($@) {
+ # try to get a writer specific module
+ my $file = "Imager/File/\U$type\EWriter.pm";
+ unless ($attempted_to_load{$file}) {
+ eval {
+ ++$attempted_to_load{$file};
+ require $file;
+ };
}
- $self->{DEBUG} && print "loading a gif file\n";
}
}
- return $self;
}
sub _fix_gif_positions {
my ($opts, $opt, $msg, @imgs) = @_;
-
+
my $positions = $opts->{'gif_positions'};
my $index = 0;
for my $pos (@$positions) {
gif_loop_count => 'gif_loop',
);
+# options that should be converted to colors
+my %color_opts = map { $_ => 1 } qw/i_background/;
+
sub _set_opts {
my ($self, $opts, $prefix, @imgs) = @_;
}
next unless $tagname =~ /^\Q$prefix/;
my $value = $opts->{$opt};
+ if ($color_opts{$opt}) {
+ $value = _color($value);
+ unless ($value) {
+ $self->_set_error($Imager::ERRSTR);
+ return;
+ }
+ }
if (ref $value) {
if (UNIVERSAL::isa($value, "Imager::Color")) {
my $tag = sprintf("color(%d,%d,%d,%d)", $value->rgba);
# Write an image to file
sub write {
my $self = shift;
- my %input=(jpegquality=>75,
- gifquant=>'mc',
- lmdither=>6.0,
+ my %input=(jpegquality=>75,
+ gifquant=>'mc',
+ lmdither=>6.0,
lmfixed=>[],
idstring=>"",
compress=>1,
$self->_set_opts(\%input, "i_", $self)
or return undef;
- my %iolready=( tiff=>1, raw=>1, png=>1, pnm=>1, bmp=>1, jpeg=>1, tga=>1,
- gif=>1 ); # this will be SO MUCH BETTER once they are all in there
-
unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; }
if (!$input{'type'} and $input{file}) {
return undef;
}
- if (!$formats{$input{'type'}}) { $self->{ERRSTR}='format not supported'; return undef; }
-
- my ($IO, $fh) = $self->_get_writer_io(\%input, $input{'type'})
- or return undef;
-
- # this conditional is probably obsolete
- if ($iolready{$input{'type'}}) {
+ _writer_autoload($input{type});
- if ($input{'type'} eq 'tiff') {
- $self->_set_opts(\%input, "tiff_", $self)
- or return undef;
- $self->_set_opts(\%input, "exif_", $self)
- or return undef;
+ my ($IO, $fh);
+ if ($writers{$input{type}} && $writers{$input{type}}{single}) {
+ ($IO, $fh) = $self->_get_writer_io(\%input, $input{'type'})
+ or return undef;
- if (defined $input{class} && $input{class} eq 'fax') {
- if (!i_writetiff_wiol_faxable($self->{IMG}, $IO, $input{fax_fine})) {
- $self->{ERRSTR}='Could not write to buffer';
- return undef;
- }
- } else {
- if (!i_writetiff_wiol($self->{IMG}, $IO)) {
- $self->{ERRSTR}='Could not write to buffer';
- return undef;
- }
- }
- } elsif ( $input{'type'} eq 'pnm' ) {
+ $writers{$input{type}}{single}->($self, $IO, %input)
+ or return undef;
+ }
+ else {
+ if (!$formats_low{$input{'type'}}) {
+ my $write_types = join ', ', sort Imager->write_types();
+ $self->_set_error("format '$input{'type'}' not supported - formats $write_types available for writing");
+ return undef;
+ }
+
+ ($IO, $fh) = $self->_get_writer_io(\%input, $input{'type'})
+ or return undef;
+
+ if ( $input{'type'} eq 'pnm' ) {
$self->_set_opts(\%input, "pnm_", $self)
or return undef;
if ( ! i_writeppm_wiol($self->{IMG},$IO) ) {
- $self->{ERRSTR}='unable to write pnm image';
- return undef;
+ $self->{ERRSTR} = $self->_error_as_msg();
+ return undef;
}
$self->{DEBUG} && print "writing a pnm file\n";
} elsif ( $input{'type'} eq 'raw' ) {
$self->_set_opts(\%input, "raw_", $self)
or return undef;
if ( !i_writeraw_wiol($self->{IMG},$IO) ) {
- $self->{ERRSTR}='unable to write raw image';
- return undef;
+ $self->{ERRSTR} = $self->_error_as_msg();
+ return undef;
}
$self->{DEBUG} && print "writing a raw file\n";
- } elsif ( $input{'type'} eq 'png' ) {
- $self->_set_opts(\%input, "png_", $self)
- or return undef;
- if ( !i_writepng_wiol($self->{IMG}, $IO) ) {
- $self->{ERRSTR}='unable to write png image';
- return undef;
- }
- $self->{DEBUG} && print "writing a png file\n";
} elsif ( $input{'type'} eq 'jpeg' ) {
$self->_set_opts(\%input, "jpeg_", $self)
or return undef;
or return undef;
if ( !i_writejpeg_wiol($self->{IMG}, $IO, $input{jpegquality})) {
$self->{ERRSTR} = $self->_error_as_msg();
- return undef;
+ return undef;
}
$self->{DEBUG} && print "writing a jpeg file\n";
} elsif ( $input{'type'} eq 'bmp' ) {
$self->_set_opts(\%input, "bmp_", $self)
or return undef;
if ( !i_writebmp_wiol($self->{IMG}, $IO) ) {
- $self->{ERRSTR}='unable to write bmp image';
- return undef;
+ $self->{ERRSTR} = $self->_error_as_msg;
+ return undef;
}
$self->{DEBUG} && print "writing a bmp file\n";
} elsif ( $input{'type'} eq 'tga' ) {
$self->_set_opts(\%input, "tga_", $self)
or return undef;
-
+
if ( !i_writetga_wiol($self->{IMG}, $IO, $input{wierdpack}, $input{compress}, $input{idstring}) ) {
- $self->{ERRSTR}=$self->_error_as_msg();
- return undef;
+ $self->{ERRSTR}=$self->_error_as_msg();
+ return undef;
}
$self->{DEBUG} && print "writing a tga file\n";
} elsif ( $input{'type'} eq 'gif' ) {
$input{make_colors} = 'webmap'; # ignored
$input{translate} = 'giflib';
}
- $rc = i_writegif_wiol($IO, \%input, $self->{IMG});
- }
-
- if (exists $input{'data'}) {
- my $data = io_slurp($IO);
- if (!$data) {
- $self->{ERRSTR}='Could not slurp from buffer';
- return undef;
+ if (!i_writegif_wiol($IO, \%input, $self->{IMG})) {
+ $self->{ERRSTR} = $self->_error_as_msg;
+ return;
}
- ${$input{data}} = $data;
}
- return $self;
}
+ if (exists $input{'data'}) {
+ my $data = io_slurp($IO);
+ if (!$data) {
+ $self->{ERRSTR}='Could not slurp from buffer';
+ return undef;
+ }
+ ${$input{data}} = $data;
+ }
return $self;
}
sub write_multi {
my ($class, $opts, @images) = @_;
- if (!$opts->{'type'} && $opts->{'file'}) {
- $opts->{'type'} = $FORMATGUESS->($opts->{'file'});
+ my $type = $opts->{type};
+
+ if (!$type && $opts->{'file'}) {
+ $type = $FORMATGUESS->($opts->{'file'});
}
- unless ($opts->{'type'}) {
+ unless ($type) {
$class->_set_error('type parameter missing and not possible to guess from extension');
return;
}
$class->_set_opts($opts, "i_", @images)
or return;
my @work = map $_->{IMG}, @images;
- my ($IO, $file) = $class->_get_writer_io($opts, $opts->{'type'})
- or return undef;
- if ($opts->{'type'} eq 'gif') {
- $class->_set_opts($opts, "gif_", @images)
- or return;
- my $gif_delays = $opts->{gif_delays};
- local $opts->{gif_delays} = $gif_delays;
- if ($opts->{gif_delays} && !ref $opts->{gif_delays}) {
- # assume the caller wants the same delay for each frame
- $opts->{gif_delays} = [ ($gif_delays) x @images ];
- }
- my $res = i_writegif_wiol($IO, $opts, @work);
- $res or $class->_set_error($class->_error_as_msg());
- return $res;
- }
- elsif ($opts->{'type'} eq 'tiff') {
- $class->_set_opts($opts, "tiff_", @images)
- or return;
- $class->_set_opts($opts, "exif_", @images)
- or return;
- my $res;
- $opts->{fax_fine} = 1 unless exists $opts->{fax_fine};
- if ($opts->{'class'} && $opts->{'class'} eq 'fax') {
- $res = i_writetiff_multi_wiol_faxable($IO, $opts->{fax_fine}, @work);
+
+ _writer_autoload($type);
+
+ my ($IO, $file);
+ if ($writers{$type} && $writers{$type}{multiple}) {
+ ($IO, $file) = $class->_get_writer_io($opts, $type)
+ or return undef;
+
+ $writers{$type}{multiple}->($class, $IO, $opts, @images)
+ or return undef;
+ }
+ else {
+ if (!$formats{$type}) {
+ my $write_types = join ', ', sort Imager->write_types();
+ $class->_set_error("format '$type' not supported - formats $write_types available for writing");
+ return undef;
+ }
+
+ ($IO, $file) = $class->_get_writer_io($opts, $type)
+ or return undef;
+
+ if (0) { # eventually PNM in here, now that TIFF/GIF are elsewhere
}
else {
- $res = i_writetiff_multi_wiol($IO, @work);
+ if (@images == 1) {
+ unless ($images[0]->write(%$opts, io => $IO, type => $type)) {
+ return 1;
+ }
+ }
+ else {
+ $ERRSTR = "Sorry, write_multi doesn't support $type yet";
+ return 0;
+ }
}
- $res or $class->_set_error($class->_error_as_msg());
- return $res;
}
- else {
- $ERRSTR = "Sorry, write_multi doesn't support $opts->{'type'} yet";
- return 0;
+
+ if (exists $opts->{'data'}) {
+ my $data = io_slurp($IO);
+ if (!$data) {
+ Imager->_set_error('Could not slurp from buffer');
+ return undef;
+ }
+ ${$opts->{data}} = $data;
}
+ return 1;
}
# read multiple images from a file
sub read_multi {
my ($class, %opts) = @_;
- if ($opts{file} && !exists $opts{'type'}) {
+ my ($IO, $file) = $class->_get_reader_io(\%opts, $opts{'type'})
+ or return;
+
+ my $type = $opts{'type'};
+ unless ($type) {
+ $type = i_test_format_probe($IO, -1);
+ }
+
+ if ($opts{file} && !$type) {
# guess the type
- my $type = $FORMATGUESS->($opts{file});
- $opts{'type'} = $type;
+ $type = $FORMATGUESS->($opts{file});
}
- unless ($opts{'type'}) {
+
+ unless ($type) {
$ERRSTR = "No type parameter supplied and it couldn't be guessed";
return;
}
- my ($IO, $file) = $class->_get_reader_io(\%opts, $opts{'type'})
- or return;
- if ($opts{'type'} eq 'gif') {
- my @imgs;
- @imgs = i_readgif_multi_wiol($IO);
- if (@imgs) {
- return map {
- bless { IMG=>$_, DEBUG=>$DEBUG, ERRSTR=>undef }, 'Imager'
- } @imgs;
- }
- else {
- $ERRSTR = _error_as_msg();
- return;
- }
+ _reader_autoload($type);
+
+ if ($readers{$type} && $readers{$type}{multiple}) {
+ return $readers{$type}{multiple}->($IO, %opts);
}
- elsif ($opts{'type'} eq 'tiff') {
- my @imgs = i_readtiff_multi_wiol($IO, -1);
- if (@imgs) {
- return map {
- bless { IMG=>$_, DEBUG=>$DEBUG, ERRSTR=>undef }, 'Imager'
- } @imgs;
- }
- else {
- $ERRSTR = _error_as_msg();
- return;
+
+ unless ($formats{$type}) {
+ my $read_types = join ', ', sort Imager->read_types();
+ Imager->_set_error("format '$type' not supported - formats $read_types available for reading");
+ return;
+ }
+
+ my @imgs;
+ if ($type eq 'pnm') {
+ @imgs = i_readpnm_multi_wiol($IO, $opts{allow_incomplete}||0);
+ }
+ else {
+ my $img = Imager->new;
+ if ($img->read(%opts, io => $IO, type => $type)) {
+ return ( $img );
}
+ Imager->_set_error($img->errstr);
+ return;
}
- $ERRSTR = "Cannot read multiple images from $opts{'type'} files";
+ if (!@imgs) {
+ $ERRSTR = _error_as_msg();
return;
+ }
+ return map {
+ bless { IMG=>$_, DEBUG=>$DEBUG, ERRSTR=>undef }, 'Imager'
+ } @imgs;
}
# Destroy an Imager object
}
}
if (defined($filters{$input{'type'}}{defaults})) {
- %hsh=('image',$self->{IMG},%{$filters{$input{'type'}}{defaults}},%input);
+ %hsh=( image => $self->{IMG},
+ imager => $self,
+ %{$filters{$input{'type'}}{defaults}},
+ %input );
} else {
- %hsh=('image',$self->{IMG},%input);
+ %hsh=( image => $self->{IMG},
+ imager => $self,
+ %input );
}
my @cs=@{$filters{$input{'type'}}{callseq}};
}
}
- &{$filters{$input{'type'}}{callsub}}(%hsh);
+ eval {
+ local $SIG{__DIE__}; # we don't want this processed by confess, etc
+ &{$filters{$input{'type'}}{callsub}}(%hsh);
+ };
+ if ($@) {
+ chomp($self->{ERRSTR} = $@);
+ return;
+ }
my @b=keys %hsh;
return $self;
}
+sub register_filter {
+ my $class = shift;
+ my %hsh = ( defaults => {}, @_ );
+
+ defined $hsh{type}
+ or die "register_filter() with no type\n";
+ defined $hsh{callsub}
+ or die "register_filter() with no callsub\n";
+ defined $hsh{callseq}
+ or die "register_filter() with no callseq\n";
+
+ exists $filters{$hsh{type}}
+ and return;
+
+ $filters{$hsh{type}} = \%hsh;
+
+ return 1;
+}
+
+sub scale_calculate {
+ my $self = shift;
+
+ my %opts = ('type'=>'max', @_);
+
+ # none of these should be references
+ for my $name (qw/xpixels ypixels xscalefactor yscalefactor width height/) {
+ if (defined $opts{$name} && ref $opts{$name}) {
+ $self->_set_error("scale_calculate: $name parameter cannot be a reference");
+ return;
+ }
+ }
+
+ my ($x_scale, $y_scale);
+ my $width = $opts{width};
+ my $height = $opts{height};
+ if (ref $self) {
+ defined $width or $width = $self->getwidth;
+ defined $height or $height = $self->getheight;
+ }
+ else {
+ unless (defined $width && defined $height) {
+ $self->_set_error("scale_calculate: width and height parameters must be supplied when called as a class method");
+ return;
+ }
+ }
+
+ if ($opts{'xscalefactor'} && $opts{'yscalefactor'}) {
+ $x_scale = $opts{'xscalefactor'};
+ $y_scale = $opts{'yscalefactor'};
+ }
+ elsif ($opts{'xscalefactor'}) {
+ $x_scale = $opts{'xscalefactor'};
+ $y_scale = $opts{'scalefactor'} || $x_scale;
+ }
+ elsif ($opts{'yscalefactor'}) {
+ $y_scale = $opts{'yscalefactor'};
+ $x_scale = $opts{'scalefactor'} || $y_scale;
+ }
+ else {
+ $x_scale = $y_scale = $opts{'scalefactor'} || 0.5;
+ }
+
+ # work out the scaling
+ if ($opts{xpixels} and $opts{ypixels} and $opts{'type'}) {
+ my ($xpix, $ypix)=( $opts{xpixels} / $width ,
+ $opts{ypixels} / $height );
+ if ($opts{'type'} eq 'min') {
+ $x_scale = $y_scale = _min($xpix,$ypix);
+ }
+ elsif ($opts{'type'} eq 'max') {
+ $x_scale = $y_scale = _max($xpix,$ypix);
+ }
+ elsif ($opts{'type'} eq 'nonprop' || $opts{'type'} eq 'non-proportional') {
+ $x_scale = $xpix;
+ $y_scale = $ypix;
+ }
+ else {
+ $self->_set_error('invalid value for type parameter');
+ return;
+ }
+ } elsif ($opts{xpixels}) {
+ $x_scale = $y_scale = $opts{xpixels} / $width;
+ }
+ elsif ($opts{ypixels}) {
+ $x_scale = $y_scale = $opts{ypixels}/$height;
+ }
+ elsif ($opts{constrain} && ref $opts{constrain}
+ && $opts{constrain}->can('constrain')) {
+ # we've been passed an Image::Math::Constrain object or something
+ # that looks like one
+ my $scalefactor;
+ (undef, undef, $scalefactor)
+ = $opts{constrain}->constrain($self->getwidth, $self->getheight);
+ unless ($scalefactor) {
+ $self->_set_error('constrain method failed on constrain parameter');
+ return;
+ }
+ $x_scale = $y_scale = $scalefactor;
+ }
+
+ my $new_width = int($x_scale * $width + 0.5);
+ $new_width > 0 or $new_width = 1;
+ my $new_height = int($y_scale * $height + 0.5);
+ $new_height > 0 or $new_height = 1;
+
+ return ($x_scale, $y_scale, $new_width, $new_height);
+
+}
+
# Scale an image to requested size and return the scaled version
sub scale {
my $self=shift;
- my %opts=(scalefactor=>0.5,'type'=>'max',qtype=>'normal',@_);
+ my %opts = (qtype=>'normal' ,@_);
my $img = Imager->new();
my $tmp = Imager->new();
- unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; }
+ unless (defined wantarray) {
+ my @caller = caller;
+ warn "scale() called in void context - scale() returns the scaled image at $caller[1] line $caller[2]\n";
+ return;
+ }
- if ($opts{xpixels} and $opts{ypixels} and $opts{'type'}) {
- my ($xpix,$ypix)=( $opts{xpixels}/$self->getwidth() , $opts{ypixels}/$self->getheight() );
- if ($opts{'type'} eq 'min') { $opts{scalefactor}=min($xpix,$ypix); }
- if ($opts{'type'} eq 'max') { $opts{scalefactor}=max($xpix,$ypix); }
- } elsif ($opts{xpixels}) { $opts{scalefactor}=$opts{xpixels}/$self->getwidth(); }
- elsif ($opts{ypixels}) { $opts{scalefactor}=$opts{ypixels}/$self->getheight(); }
+ unless ($self->{IMG}) {
+ $self->_set_error('empty input image');
+ return undef;
+ }
+
+ my ($x_scale, $y_scale, $new_width, $new_height) =
+ $self->scale_calculate(%opts)
+ or return;
if ($opts{qtype} eq 'normal') {
- $tmp->{IMG}=i_scaleaxis($self->{IMG},$opts{scalefactor},0);
- if ( !defined($tmp->{IMG}) ) { $self->{ERRSTR}='unable to scale image'; return undef; }
- $img->{IMG}=i_scaleaxis($tmp->{IMG},$opts{scalefactor},1);
- if ( !defined($img->{IMG}) ) { $self->{ERRSTR}='unable to scale image'; return undef; }
+ $tmp->{IMG} = i_scaleaxis($self->{IMG}, $x_scale, 0);
+ if ( !defined($tmp->{IMG}) ) {
+ $self->{ERRSTR} = 'unable to scale image: ' . $self->_error_as_msg;
+ return undef;
+ }
+ $img->{IMG}=i_scaleaxis($tmp->{IMG}, $y_scale, 1);
+ if ( !defined($img->{IMG}) ) {
+ $self->{ERRSTR}='unable to scale image: ' . $self->_error_as_msg;
+ return undef;
+ }
+
+ return $img;
+ }
+ elsif ($opts{'qtype'} eq 'preview') {
+ $img->{IMG} = i_scale_nn($self->{IMG}, $x_scale, $y_scale);
+ if ( !defined($img->{IMG}) ) {
+ $self->{ERRSTR}='unable to scale image';
+ return undef;
+ }
return $img;
}
- if ($opts{'qtype'} eq 'preview') {
- $img->{IMG}=i_scale_nn($self->{IMG},$opts{'scalefactor'},$opts{'scalefactor'});
- if ( !defined($img->{IMG}) ) { $self->{ERRSTR}='unable to scale image'; return undef; }
+ elsif ($opts{'qtype'} eq 'mixing') {
+ $img->{IMG} = i_scale_mixing($self->{IMG}, $new_width, $new_height);
+ unless ($img->{IMG}) {
+ $self->_set_error(Imager->_error_as_msg);
+ return;
+ }
return $img;
}
- $self->{ERRSTR}='scale: invalid value for qtype'; return undef;
+ else {
+ $self->_set_error('invalid value for qtype parameter');
+ return undef;
+ }
}
# Scales only along the X axis
sub scaleX {
- my $self=shift;
- my %opts=(scalefactor=>0.5,@_);
+ my $self = shift;
+ my %opts = ( scalefactor=>0.5, @_ );
- unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; }
+ unless (defined wantarray) {
+ my @caller = caller;
+ warn "scaleX() called in void context - scaleX() returns the scaled image at $caller[1] line $caller[2]\n";
+ return;
+ }
+
+ unless ($self->{IMG}) {
+ $self->{ERRSTR} = 'empty input image';
+ return undef;
+ }
my $img = Imager->new();
- if ($opts{pixels}) { $opts{scalefactor}=$opts{pixels}/$self->getwidth(); }
+ my $scalefactor = $opts{scalefactor};
- unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; }
- $img->{IMG}=i_scaleaxis($self->{IMG},$opts{scalefactor},0);
+ if ($opts{pixels}) {
+ $scalefactor = $opts{pixels} / $self->getwidth();
+ }
+
+ unless ($self->{IMG}) {
+ $self->{ERRSTR}='empty input image';
+ return undef;
+ }
+
+ $img->{IMG} = i_scaleaxis($self->{IMG}, $scalefactor, 0);
+
+ if ( !defined($img->{IMG}) ) {
+ $self->{ERRSTR} = 'unable to scale image';
+ return undef;
+ }
- if ( !defined($img->{IMG}) ) { $self->{ERRSTR}='unable to scale image'; return undef; }
return $img;
}
# Scales only along the Y axis
sub scaleY {
- my $self=shift;
- my %opts=(scalefactor=>0.5,@_);
+ my $self = shift;
+ my %opts = ( scalefactor => 0.5, @_ );
+
+ unless (defined wantarray) {
+ my @caller = caller;
+ warn "scaleY() called in void context - scaleY() returns the scaled image at $caller[1] line $caller[2]\n";
+ return;
+ }
unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; }
my $img = Imager->new();
- if ($opts{pixels}) { $opts{scalefactor}=$opts{pixels}/$self->getheight(); }
+ my $scalefactor = $opts{scalefactor};
- unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; }
- $img->{IMG}=i_scaleaxis($self->{IMG},$opts{scalefactor},1);
+ if ($opts{pixels}) {
+ $scalefactor = $opts{pixels} / $self->getheight();
+ }
+
+ unless ($self->{IMG}) {
+ $self->{ERRSTR} = 'empty input image';
+ return undef;
+ }
+ $img->{IMG}=i_scaleaxis($self->{IMG}, $scalefactor, 1);
+
+ if ( !defined($img->{IMG}) ) {
+ $self->{ERRSTR} = 'unable to scale image';
+ return undef;
+ }
- if ( !defined($img->{IMG}) ) { $self->{ERRSTR}='unable to scale image'; return undef; }
return $img;
}
-
# Transform returns a spatial transformation of the input image
# this moves pixels to a new location in the returned image.
# NOTE - should make a utility function to check transforms for
$Imager::ERRSTR = Imager::Expr::error();
return;
}
+ my $channels = $opts->{channels} || 3;
+ unless ($channels >= 1 && $channels <= 4) {
+ return Imager->_set_error("channels must be an integer between 1 and 4");
+ }
my $img = Imager->new();
- $img->{IMG} = i_transform2($opts->{width}, $opts->{height}, $code->code(),
+ $img->{IMG} = i_transform2($opts->{width}, $opts->{height},
+ $channels, $code->code(),
$code->nregs(), $code->cregs(),
[ map { $_->{IMG} } @imgs ]);
if (!defined $img->{IMG}) {
sub rubthrough {
my $self=shift;
- my %opts=(tx=>0,ty=>0,@_);
-
- unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; }
- unless ($opts{src} && $opts{src}->{IMG}) { $self->{ERRSTR}='empty input image for source'; return undef; }
+ my %opts= @_;
- unless (i_rubthru($self->{IMG}, $opts{src}->{IMG}, $opts{tx},$opts{ty})) {
- $self->{ERRSTR} = $self->_error_as_msg();
+ unless ($self->{IMG}) {
+ $self->{ERRSTR}='empty input image';
return undef;
}
+ unless ($opts{src} && $opts{src}->{IMG}) {
+ $self->{ERRSTR}='empty input image for src';
+ return undef;
+ }
+
+ %opts = (src_minx => 0,
+ src_miny => 0,
+ src_maxx => $opts{src}->getwidth(),
+ src_maxy => $opts{src}->getheight(),
+ %opts);
+
+ my $tx = $opts{tx};
+ defined $tx or $tx = $opts{left};
+ defined $tx or $tx = 0;
+
+ my $ty = $opts{ty};
+ defined $ty or $ty = $opts{top};
+ defined $ty or $ty = 0;
+
+ unless (i_rubthru($self->{IMG}, $opts{src}->{IMG}, $tx, $ty,
+ $opts{src_minx}, $opts{src_miny},
+ $opts{src_maxx}, $opts{src_maxy})) {
+ $self->_set_error($self->_error_as_msg());
+ return undef;
+ }
+
return $self;
}
+sub compose {
+ my $self = shift;
+ my %opts =
+ (
+ opacity => 1.0,
+ mask_left => 0,
+ mask_top => 0,
+ @_
+ );
+
+ unless ($self->{IMG}) {
+ $self->_set_error("compose: empty input image");
+ return;
+ }
+
+ unless ($opts{src}) {
+ $self->_set_error("compose: src parameter missing");
+ return;
+ }
+
+ unless ($opts{src}{IMG}) {
+ $self->_set_error("compose: src parameter empty image");
+ return;
+ }
+ my $src = $opts{src};
+
+ my $left = $opts{left};
+ defined $left or $left = $opts{tx};
+ defined $left or $left = 0;
+
+ my $top = $opts{top};
+ defined $top or $top = $opts{ty};
+ defined $top or $top = 0;
+
+ my $src_left = $opts{src_left};
+ defined $src_left or $src_left = $opts{src_minx};
+ defined $src_left or $src_left = 0;
+
+ my $src_top = $opts{src_top};
+ defined $src_top or $src_top = $opts{src_miny};
+ defined $src_top or $src_top = 0;
+
+ my $width = $opts{width};
+ if (!defined $width && defined $opts{src_maxx}) {
+ $width = $opts{src_maxx} - $src_left;
+ }
+ defined $width or $width = $src->getwidth() - $src_left;
+
+ my $height = $opts{height};
+ if (!defined $height && defined $opts{src_maxy}) {
+ $height = $opts{src_maxy} - $src_top;
+ }
+ defined $height or $height = $src->getheight() - $src_top;
+
+ my $combine = $self->_combine($opts{combine}, 'normal');
+
+ if ($opts{mask}) {
+ unless ($opts{mask}{IMG}) {
+ $self->_set_error("compose: mask parameter empty image");
+ return;
+ }
+
+ my $mask_left = $opts{mask_left};
+ defined $mask_left or $mask_left = $opts{mask_minx};
+ defined $mask_left or $mask_left = 0;
+
+ my $mask_top = $opts{mask_top};
+ defined $mask_top or $mask_top = $opts{mask_miny};
+ defined $mask_top or $mask_top = 0;
+
+ i_compose_mask($self->{IMG}, $src->{IMG}, $opts{mask}{IMG},
+ $left, $top, $src_left, $src_top,
+ $mask_left, $mask_top, $width, $height,
+ $combine, $opts{opacity})
+ or return;
+ }
+ else {
+ i_compose($self->{IMG}, $src->{IMG}, $left, $top, $src_left, $src_top,
+ $width, $height, $combine, $opts{opacity})
+ or return;
+ }
+
+ return $self;
+}
sub flip {
my $self = shift;
sub rotate {
my $self = shift;
my %opts = @_;
+
+ unless (defined wantarray) {
+ my @caller = caller;
+ warn "rotate() called in void context - rotate() returns the rotated image at $caller[1] line $caller[2]\n";
+ return;
+ }
+
if (defined $opts{right}) {
my $degrees = $opts{right};
if ($degrees < 0) {
elsif (defined $opts{radians} || defined $opts{degrees}) {
my $amount = $opts{radians} || $opts{degrees} * 3.1415926535 / 180;
+ my $back = $opts{back};
my $result = Imager->new;
- if ($result->{IMG} = i_rotate_exact($self->{IMG}, $amount)) {
+ if ($back) {
+ $back = _color($back);
+ unless ($back) {
+ $self->_set_error(Imager->errstr);
+ return undef;
+ }
+
+ $result->{IMG} = i_rotate_exact($self->{IMG}, $amount, $back);
+ }
+ else {
+ $result->{IMG} = i_rotate_exact($self->{IMG}, $amount);
+ }
+ if ($result->{IMG}) {
return $result;
}
else {
}
}
else {
- $self->{ERRSTR} = "Only the 'right' parameter is available";
+ $self->{ERRSTR} = "Only the 'right', 'radians' and 'degrees' parameters are available";
return undef;
}
}
my $self = shift;
my %opts = @_;
+ unless (defined wantarray) {
+ my @caller = caller;
+ warn "copy() called in void context - copy() returns the copied image at $caller[1] line $caller[2]\n";
+ return;
+ }
+
if ($opts{matrix}) {
my $xsize = $opts{xsize} || $self->getwidth;
my $ysize = $opts{ysize} || $self->getheight;
my $result = Imager->new;
- $result->{IMG} = i_matrix_transform($self->{IMG}, $xsize, $ysize,
- $opts{matrix})
- or return undef;
+ if ($opts{back}) {
+ $result->{IMG} = i_matrix_transform($self->{IMG}, $xsize, $ysize,
+ $opts{matrix}, $opts{back})
+ or return undef;
+ }
+ else {
+ $result->{IMG} = i_matrix_transform($self->{IMG}, $xsize, $ysize,
+ $opts{matrix})
+ or return undef;
+ }
return $result;
}
# Draws a box between the specified corner points.
sub box {
my $self=shift;
- unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; }
- my $dflcl=i_color_new(255,255,255,255);
- my %opts=(color=>$dflcl,xmin=>0,ymin=>0,xmax=>$self->getwidth()-1,ymax=>$self->getheight()-1,@_);
+ my $raw = $self->{IMG};
+
+ unless ($raw) {
+ $self->{ERRSTR}='empty input image';
+ return undef;
+ }
+ my %opts = @_;
+
+ my ($xmin, $ymin, $xmax, $ymax);
if (exists $opts{'box'}) {
- $opts{'xmin'} = min($opts{'box'}->[0],$opts{'box'}->[2]);
- $opts{'xmax'} = max($opts{'box'}->[0],$opts{'box'}->[2]);
- $opts{'ymin'} = min($opts{'box'}->[1],$opts{'box'}->[3]);
- $opts{'ymax'} = max($opts{'box'}->[1],$opts{'box'}->[3]);
+ $xmin = _min($opts{'box'}->[0],$opts{'box'}->[2]);
+ $xmax = _max($opts{'box'}->[0],$opts{'box'}->[2]);
+ $ymin = _min($opts{'box'}->[1],$opts{'box'}->[3]);
+ $ymax = _max($opts{'box'}->[1],$opts{'box'}->[3]);
+ }
+ else {
+ defined($xmin = $opts{xmin}) or $xmin = 0;
+ defined($xmax = $opts{xmax}) or $xmax = $self->getwidth()-1;
+ defined($ymin = $opts{ymin}) or $ymin = 0;
+ defined($ymax = $opts{ymax}) or $ymax = $self->getheight()-1;
}
if ($opts{filled}) {
- my $color = _color($opts{'color'});
- unless ($color) {
- $self->{ERRSTR} = $Imager::ERRSTR;
- return;
+ my $color = $opts{'color'};
+
+ if (defined $color) {
+ unless (_is_color_object($color)) {
+ $color = _color($color);
+ unless ($color) {
+ $self->{ERRSTR} = $Imager::ERRSTR;
+ return;
+ }
+ }
+ }
+ else {
+ $color = i_color_new(255,255,255,255);
}
- i_box_filled($self->{IMG},$opts{xmin},$opts{ymin},$opts{xmax},
- $opts{ymax}, $color);
+
+ i_box_filled($raw, $xmin, $ymin,$xmax, $ymax, $color);
}
elsif ($opts{fill}) {
unless (UNIVERSAL::isa($opts{fill}, 'Imager::Fill')) {
return undef;
}
}
- i_box_cfill($self->{IMG},$opts{xmin},$opts{ymin},$opts{xmax},
- $opts{ymax},$opts{fill}{fill});
+ i_box_cfill($raw, $xmin, $ymin, $xmax, $ymax, $opts{fill}{fill});
}
else {
- my $color = _color($opts{'color'});
+ my $color = $opts{'color'};
+ if (defined $color) {
+ unless (_is_color_object($color)) {
+ $color = _color($color);
+ unless ($color) {
+ $self->{ERRSTR} = $Imager::ERRSTR;
+ return;
+ }
+ }
+ }
+ else {
+ $color = i_color_new(255, 255, 255, 255);
+ }
unless ($color) {
$self->{ERRSTR} = $Imager::ERRSTR;
return;
}
- i_box($self->{IMG},$opts{xmin},$opts{ymin},$opts{xmax},$opts{ymax},
- $color);
+ i_box($raw, $xmin, $ymin, $xmax, $ymax, $color);
}
+
return $self;
}
-# Draws an arc - this routine SUCKS and is buggy - it sometimes doesn't work when the arc is a convex polygon
-
sub arc {
my $self=shift;
unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; }
- my $dflcl=i_color_new(255,255,255,255);
- my %opts=(color=>$dflcl,
- 'r'=>min($self->getwidth(),$self->getheight())/3,
- 'x'=>$self->getwidth()/2,
- 'y'=>$self->getheight()/2,
- 'd1'=>0, 'd2'=>361, @_);
- if ($opts{fill}) {
- unless (UNIVERSAL::isa($opts{fill}, 'Imager::Fill')) {
- # assume it's a hash ref
- require 'Imager/Fill.pm';
- unless ($opts{fill} = Imager::Fill->new(%{$opts{fill}})) {
- $self->{ERRSTR} = $Imager::ERRSTR;
- return;
+ my $dflcl= [ 255, 255, 255, 255];
+ my $good = 1;
+ my %opts=
+ (
+ color=>$dflcl,
+ 'r'=>_min($self->getwidth(),$self->getheight())/3,
+ 'x'=>$self->getwidth()/2,
+ 'y'=>$self->getheight()/2,
+ 'd1'=>0, 'd2'=>361,
+ filled => 1,
+ @_,
+ );
+ if ($opts{aa}) {
+ if ($opts{fill}) {
+ unless (UNIVERSAL::isa($opts{fill}, 'Imager::Fill')) {
+ # assume it's a hash ref
+ require 'Imager/Fill.pm';
+ unless ($opts{fill} = Imager::Fill->new(%{$opts{fill}})) {
+ $self->{ERRSTR} = $Imager::ERRSTR;
+ return;
+ }
+ }
+ i_arc_aa_cfill($self->{IMG},$opts{'x'},$opts{'y'},$opts{'r'},$opts{'d1'},
+ $opts{'d2'}, $opts{fill}{fill});
+ }
+ elsif ($opts{filled}) {
+ my $color = _color($opts{'color'});
+ unless ($color) {
+ $self->{ERRSTR} = $Imager::ERRSTR;
+ return;
+ }
+ if ($opts{d1} == 0 && $opts{d2} == 361 && $opts{aa}) {
+ i_circle_aa($self->{IMG}, $opts{'x'}, $opts{'y'}, $opts{'r'},
+ $color);
+ }
+ else {
+ i_arc_aa($self->{IMG},$opts{'x'},$opts{'y'},$opts{'r'},
+ $opts{'d1'}, $opts{'d2'}, $color);
+ }
+ }
+ else {
+ my $color = _color($opts{'color'});
+ if ($opts{d2} - $opts{d1} >= 360) {
+ $good = i_circle_out_aa($self->{IMG}, $opts{'x'}, $opts{'y'}, $opts{'r'}, $color);
+ }
+ else {
+ $good = i_arc_out_aa($self->{IMG}, $opts{'x'}, $opts{'y'}, $opts{'r'}, $opts{'d1'}, $opts{'d2'}, $color);
}
}
- i_arc_cfill($self->{IMG},$opts{'x'},$opts{'y'},$opts{'r'},$opts{'d1'},
- $opts{'d2'}, $opts{fill}{fill});
}
else {
- my $color = _color($opts{'color'});
- unless ($color) {
- $self->{ERRSTR} = $Imager::ERRSTR;
- return;
- }
- if ($opts{d1} == 0 && $opts{d2} == 361 && $opts{aa}) {
- i_circle_aa($self->{IMG}, $opts{'x'}, $opts{'y'}, $opts{'r'},
- $color);
+ if ($opts{fill}) {
+ unless (UNIVERSAL::isa($opts{fill}, 'Imager::Fill')) {
+ # assume it's a hash ref
+ require 'Imager/Fill.pm';
+ unless ($opts{fill} = Imager::Fill->new(%{$opts{fill}})) {
+ $self->{ERRSTR} = $Imager::ERRSTR;
+ return;
+ }
+ }
+ i_arc_cfill($self->{IMG},$opts{'x'},$opts{'y'},$opts{'r'},$opts{'d1'},
+ $opts{'d2'}, $opts{fill}{fill});
}
else {
- if ($opts{'d1'} <= $opts{'d2'}) {
- i_arc($self->{IMG},$opts{'x'},$opts{'y'},$opts{'r'},
- $opts{'d1'}, $opts{'d2'}, $color);
+ my $color = _color($opts{'color'});
+ unless ($color) {
+ $self->{ERRSTR} = $Imager::ERRSTR;
+ return;
+ }
+ if ($opts{filled}) {
+ i_arc($self->{IMG},$opts{'x'},$opts{'y'},$opts{'r'},
+ $opts{'d1'}, $opts{'d2'}, $color);
}
else {
- i_arc($self->{IMG},$opts{'x'},$opts{'y'},$opts{'r'},
- $opts{'d1'}, 361, $color);
- i_arc($self->{IMG},$opts{'x'},$opts{'y'},$opts{'r'},
- 0, $opts{'d2'}, $color);
+ if ($opts{d1} == 0 && $opts{d2} == 361) {
+ $good = i_circle_out($self->{IMG}, $opts{x}, $opts{y}, $opts{r}, $color);
+ }
+ else {
+ $good = i_arc_out($self->{IMG}, $opts{x}, $opts{y}, $opts{r}, $opts{d1}, $opts{d2}, $color);
+ }
}
}
}
+ unless ($good) {
+ $self->_set_error($self->_error_as_msg);
+ return;
+ }
return $self;
}
return undef;
}
- if ($opts{fill}) {
- unless (UNIVERSAL::isa($opts{fill}, 'Imager::Fill')) {
- # assume it's a hash ref
- require 'Imager/Fill.pm';
- unless ($opts{fill} = Imager::Fill->new(%{$opts{fill}})) {
- $self->{ERRSTR} = $Imager::ERRSTR;
- return;
+ if ($opts{border}) {
+ my $border = _color($opts{border});
+ unless ($border) {
+ $self->_set_error($Imager::ERRSTR);
+ return;
+ }
+ if ($opts{fill}) {
+ unless (UNIVERSAL::isa($opts{fill}, 'Imager::Fill')) {
+ # assume it's a hash ref
+ require Imager::Fill;
+ unless ($opts{fill} = Imager::Fill->new(%{$opts{fill}})) {
+ $self->{ERRSTR} = $Imager::ERRSTR;
+ return;
+ }
+ }
+ $rc = i_flood_cfill_border($self->{IMG}, $opts{'x'}, $opts{'y'},
+ $opts{fill}{fill}, $border);
+ }
+ else {
+ my $color = _color($opts{'color'});
+ unless ($color) {
+ $self->{ERRSTR} = $Imager::ERRSTR;
+ return;
}
+ $rc = i_flood_fill_border($self->{IMG}, $opts{'x'}, $opts{'y'},
+ $color, $border);
+ }
+ if ($rc) {
+ return $self;
+ }
+ else {
+ $self->{ERRSTR} = $self->_error_as_msg();
+ return;
}
- $rc = i_flood_cfill($self->{IMG}, $opts{'x'}, $opts{'y'}, $opts{fill}{fill});
}
else {
- my $color = _color($opts{'color'});
- unless ($color) {
- $self->{ERRSTR} = $Imager::ERRSTR;
+ if ($opts{fill}) {
+ unless (UNIVERSAL::isa($opts{fill}, 'Imager::Fill')) {
+ # assume it's a hash ref
+ require 'Imager/Fill.pm';
+ unless ($opts{fill} = Imager::Fill->new(%{$opts{fill}})) {
+ $self->{ERRSTR} = $Imager::ERRSTR;
+ return;
+ }
+ }
+ $rc = i_flood_cfill($self->{IMG}, $opts{'x'}, $opts{'y'}, $opts{fill}{fill});
+ }
+ else {
+ my $color = _color($opts{'color'});
+ unless ($color) {
+ $self->{ERRSTR} = $Imager::ERRSTR;
+ return;
+ }
+ $rc = i_flood_fill($self->{IMG}, $opts{'x'}, $opts{'y'}, $color);
+ }
+ if ($rc) {
+ return $self;
+ }
+ else {
+ $self->{ERRSTR} = $self->_error_as_msg();
return;
}
- $rc = i_flood_fill($self->{IMG}, $opts{'x'}, $opts{'y'}, $color);
- }
- if ($rc) { $self; } else { $self->{ERRSTR} = $self->_error_as_msg(); return (); }
+ }
}
sub setpixel {
- my $self = shift;
+ my ($self, %opts) = @_;
+
+ my $color = $opts{color};
+ unless (defined $color) {
+ $color = $self->{fg};
+ defined $color or $color = NC(255, 255, 255);
+ }
- my %opts = ( color=>$self->{fg} || NC(255, 255, 255), @_);
+ unless (ref $color && UNIVERSAL::isa($color, "Imager::Color")) {
+ $color = _color($color)
+ or return undef;
+ }
unless (exists $opts{'x'} && exists $opts{'y'}) {
$self->{ERRSTR} = 'missing x and y parameters';
my $x = $opts{'x'};
my $y = $opts{'y'};
- my $color = _color($opts{color})
- or return undef;
if (ref $x && ref $y) {
unless (@$x == @$y) {
$self->{ERRSTR} = 'length of x and y mismatch';
- return undef;
+ return;
}
+ my $set = 0;
if ($color->isa('Imager::Color')) {
for my $i (0..$#{$opts{'x'}}) {
- i_ppix($self->{IMG}, $x->[$i], $y->[$i], $color);
+ i_ppix($self->{IMG}, $x->[$i], $y->[$i], $color)
+ or ++$set;
}
}
else {
for my $i (0..$#{$opts{'x'}}) {
- i_ppixf($self->{IMG}, $x->[$i], $y->[$i], $color);
+ i_ppixf($self->{IMG}, $x->[$i], $y->[$i], $color)
+ or ++$set;
}
}
+ $set or return;
+ return $set;
}
else {
if ($color->isa('Imager::Color')) {
- i_ppix($self->{IMG}, $x, $y, $color);
+ i_ppix($self->{IMG}, $x, $y, $color)
+ and return;
}
else {
- i_ppixf($self->{IMG}, $x, $y, $color);
+ i_ppixf($self->{IMG}, $x, $y, $color)
+ and return;
}
}
$self;
}
+sub getscanline {
+ my $self = shift;
+ my %opts = ( type => '8bit', x=>0, @_);
+
+ $self->_valid_image or return;
+
+ defined $opts{width} or $opts{width} = $self->getwidth - $opts{x};
+
+ unless (defined $opts{'y'}) {
+ $self->_set_error("missing y parameter");
+ return;
+ }
+
+ if ($opts{type} eq '8bit') {
+ return i_glin($self->{IMG}, $opts{x}, $opts{x}+$opts{width},
+ $opts{'y'});
+ }
+ elsif ($opts{type} eq 'float') {
+ return i_glinf($self->{IMG}, $opts{x}, $opts{x}+$opts{width},
+ $opts{'y'});
+ }
+ elsif ($opts{type} eq 'index') {
+ unless (i_img_type($self->{IMG})) {
+ $self->_set_error("type => index only valid on paletted images");
+ return;
+ }
+ return i_gpal($self->{IMG}, $opts{x}, $opts{x} + $opts{width},
+ $opts{'y'});
+ }
+ else {
+ $self->_set_error("invalid type parameter - must be '8bit' or 'float'");
+ return;
+ }
+}
+
+sub setscanline {
+ my $self = shift;
+ my %opts = ( x=>0, @_);
+
+ $self->_valid_image or return;
+
+ unless (defined $opts{'y'}) {
+ $self->_set_error("missing y parameter");
+ return;
+ }
+
+ if (!$opts{type}) {
+ if (ref $opts{pixels} && @{$opts{pixels}}) {
+ # try to guess the type
+ if ($opts{pixels}[0]->isa('Imager::Color')) {
+ $opts{type} = '8bit';
+ }
+ elsif ($opts{pixels}[0]->isa('Imager::Color::Float')) {
+ $opts{type} = 'float';
+ }
+ else {
+ $self->_set_error("missing type parameter and could not guess from pixels");
+ return;
+ }
+ }
+ else {
+ # default
+ $opts{type} = '8bit';
+ }
+ }
+
+ if ($opts{type} eq '8bit') {
+ if (ref $opts{pixels}) {
+ return i_plin($self->{IMG}, $opts{x}, $opts{'y'}, @{$opts{pixels}});
+ }
+ else {
+ return i_plin($self->{IMG}, $opts{x}, $opts{'y'}, $opts{pixels});
+ }
+ }
+ elsif ($opts{type} eq 'float') {
+ if (ref $opts{pixels}) {
+ return i_plinf($self->{IMG}, $opts{x}, $opts{'y'}, @{$opts{pixels}});
+ }
+ else {
+ return i_plinf($self->{IMG}, $opts{x}, $opts{'y'}, $opts{pixels});
+ }
+ }
+ elsif ($opts{type} eq 'index') {
+ if (ref $opts{pixels}) {
+ return i_ppal($self->{IMG}, $opts{x}, $opts{'y'}, @{$opts{pixels}});
+ }
+ else {
+ return i_ppal_p($self->{IMG}, $opts{x}, $opts{'y'}, $opts{pixels});
+ }
+ }
+ else {
+ $self->_set_error("invalid type parameter - must be '8bit' or 'float'");
+ return;
+ }
+}
+
+sub getsamples {
+ my $self = shift;
+ my %opts = ( type => '8bit', x=>0, offset => 0, @_);
+
+ defined $opts{width} or $opts{width} = $self->getwidth - $opts{x};
+
+ unless (defined $opts{'y'}) {
+ $self->_set_error("missing y parameter");
+ return;
+ }
+
+ unless ($opts{channels}) {
+ $opts{channels} = [ 0 .. $self->getchannels()-1 ];
+ }
+
+ if ($opts{target}) {
+ my $target = $opts{target};
+ my $offset = $opts{offset};
+ if ($opts{type} eq '8bit') {
+ my @samples = i_gsamp($self->{IMG}, $opts{x}, $opts{x}+$opts{width},
+ $opts{y}, @{$opts{channels}})
+ or return;
+ @{$target}{$offset .. $offset + @samples - 1} = @samples;
+ return scalar(@samples);
+ }
+ elsif ($opts{type} eq 'float') {
+ my @samples = i_gsampf($self->{IMG}, $opts{x}, $opts{x}+$opts{width},
+ $opts{y}, @{$opts{channels}});
+ @{$target}{$offset .. $offset + @samples - 1} = @samples;
+ return scalar(@samples);
+ }
+ elsif ($opts{type} =~ /^(\d+)bit$/) {
+ my $bits = $1;
+
+ my @data;
+ my $count = i_gsamp_bits($self->{IMG}, $opts{x}, $opts{x}+$opts{width},
+ $opts{y}, $bits, $target,
+ $offset, @{$opts{channels}});
+ unless (defined $count) {
+ $self->_set_error(Imager->_error_as_msg);
+ return;
+ }
+
+ return $count;
+ }
+ else {
+ $self->_set_error("invalid type parameter - must be '8bit' or 'float'");
+ return;
+ }
+ }
+ else {
+ if ($opts{type} eq '8bit') {
+ return i_gsamp($self->{IMG}, $opts{x}, $opts{x}+$opts{width},
+ $opts{y}, @{$opts{channels}});
+ }
+ elsif ($opts{type} eq 'float') {
+ return i_gsampf($self->{IMG}, $opts{x}, $opts{x}+$opts{width},
+ $opts{y}, @{$opts{channels}});
+ }
+ elsif ($opts{type} =~ /^(\d+)bit$/) {
+ my $bits = $1;
+
+ my @data;
+ i_gsamp_bits($self->{IMG}, $opts{x}, $opts{x}+$opts{width},
+ $opts{y}, $bits, \@data, 0, @{$opts{channels}})
+ or return;
+ return @data;
+ }
+ else {
+ $self->_set_error("invalid type parameter - must be '8bit' or 'float'");
+ return;
+ }
+ }
+}
+
+sub setsamples {
+ my $self = shift;
+ my %opts = ( x => 0, offset => 0, @_ );
+
+ unless ($self->{IMG}) {
+ $self->_set_error('setsamples: empty input image');
+ return;
+ }
+
+ unless(defined $opts{data} && ref $opts{data}) {
+ $self->_set_error('setsamples: data parameter missing or invalid');
+ return;
+ }
+
+ unless ($opts{channels}) {
+ $opts{channels} = [ 0 .. $self->getchannels()-1 ];
+ }
+
+ unless ($opts{type} && $opts{type} =~ /^(\d+)bit$/) {
+ $self->_set_error('setsamples: type parameter missing or invalid');
+ return;
+ }
+ my $bits = $1;
+
+ unless (defined $opts{width}) {
+ $opts{width} = $self->getwidth() - $opts{x};
+ }
+
+ my $count = i_psamp_bits($self->{IMG}, $opts{x}, $opts{y}, $bits,
+ $opts{channels}, $opts{data}, $opts{offset},
+ $opts{width});
+ unless (defined $count) {
+ $self->_set_error(Imager->_error_as_msg);
+ return;
+ }
+
+ return $count;
+}
+
# make an identity matrix of the given size
sub _identity {
my ($size) = @_;
my ($self, %opts) = @_;
my $matrix;
+ unless (defined wantarray) {
+ my @caller = caller;
+ warn "convert() called in void context - convert() returns the converted image at $caller[1] line $caller[2]\n";
+ return;
+ }
+
# the user can either specify a matrix or preset
# the matrix overrides the preset
if (!exists($opts{matrix})) {
$matrix = $opts{matrix};
}
- my $new = Imager->new();
- $new->{IMG} = i_img_new();
- unless (i_convert($new->{IMG}, $self->{IMG}, $matrix)) {
+ my $new = Imager->new;
+ $new->{IMG} = i_convert($self->{IMG}, $matrix);
+ unless ($new->{IMG}) {
# most likely a bad matrix
$self->{ERRSTR} = _error_as_msg();
return undef;
return $new;
}
+# combine channels from multiple input images, a class method
+sub combine {
+ my ($class, %opts) = @_;
-# general function to map an image through lookup tables
-
-sub map {
- my ($self, %opts) = @_;
- my @chlist = qw( red green blue alpha );
-
- if (!exists($opts{'maps'})) {
- # make maps from channel maps
- my $chnum;
- for $chnum (0..$#chlist) {
- if (exists $opts{$chlist[$chnum]}) {
- $opts{'maps'}[$chnum] = $opts{$chlist[$chnum]};
- } elsif (exists $opts{'all'}) {
+ my $src = delete $opts{src};
+ unless ($src) {
+ $class->_set_error("src parameter missing");
+ return;
+ }
+ my @imgs;
+ my $index = 0;
+ for my $img (@$src) {
+ unless (eval { $img->isa("Imager") }) {
+ $class->_set_error("src must contain image objects");
+ return;
+ }
+ unless ($img->{IMG}) {
+ $class->_set_error("empty input image");
+ return;
+ }
+ push @imgs, $img->{IMG};
+ }
+ my $result;
+ if (my $channels = delete $opts{channels}) {
+ $result = i_combine(\@imgs, $channels);
+ }
+ else {
+ $result = i_combine(\@imgs);
+ }
+ unless ($result) {
+ $class->_set_error($class->_error_as_msg);
+ return;
+ }
+
+ my $img = $class->new;
+ $img->{IMG} = $result;
+
+ return $img;
+}
+
+
+# general function to map an image through lookup tables
+
+sub map {
+ my ($self, %opts) = @_;
+ my @chlist = qw( red green blue alpha );
+
+ if (!exists($opts{'maps'})) {
+ # make maps from channel maps
+ my $chnum;
+ for $chnum (0..$#chlist) {
+ if (exists $opts{$chlist[$chnum]}) {
+ $opts{'maps'}[$chnum] = $opts{$chlist[$chnum]};
+ } elsif (exists $opts{'all'}) {
$opts{'maps'}[$chnum] = $opts{'all'};
}
}
sub getwidth {
my $self = shift;
- if (!defined($self->{IMG})) { $self->{ERRSTR} = 'image is empty'; return undef; }
- return (i_img_info($self->{IMG}))[0];
+
+ if (my $raw = $self->{IMG}) {
+ return i_img_get_width($raw);
+ }
+ else {
+ $self->{ERRSTR} = 'image is empty'; return undef;
+ }
}
# Get the height of an image
sub getheight {
my $self = shift;
- if (!defined($self->{IMG})) { $self->{ERRSTR} = 'image is empty'; return undef; }
- return (i_img_info($self->{IMG}))[1];
+
+ if (my $raw = $self->{IMG}) {
+ return i_img_get_height($raw);
+ }
+ else {
+ $self->{ERRSTR} = 'image is empty'; return undef;
+ }
}
# Get number of channels in an image
sub setmask {
my $self = shift;
my %opts = @_;
- if (!defined($self->{IMG})) { $self->{ERRSTR} = 'image is empty'; return undef; }
+ if (!defined($self->{IMG})) {
+ $self->{ERRSTR} = 'image is empty';
+ return undef;
+ }
+ unless (defined $opts{mask}) {
+ $self->_set_error("mask parameter required");
+ return;
+ }
i_img_setmask( $self->{IMG} , $opts{mask} );
+
+ 1;
}
# Get number of colors in an image
return ($rc==-1? undef : $rc);
}
+# Returns a reference to a hash. The keys are colour named (packed) and the
+# values are the number of pixels in this colour.
+sub getcolorusagehash {
+ my $self = shift;
+
+ my %opts = ( maxcolors => 2**30, @_ );
+ my $max_colors = $opts{maxcolors};
+ unless (defined $max_colors && $max_colors > 0) {
+ $self->_set_error('maxcolors must be a positive integer');
+ return;
+ }
+
+ unless (defined $self->{IMG}) {
+ $self->_set_error('empty input image');
+ return;
+ }
+
+ my $channels= $self->getchannels;
+ # We don't want to look at the alpha channel, because some gifs using it
+ # doesn't define it for every colour (but only for some)
+ $channels -= 1 if $channels == 2 or $channels == 4;
+ my %color_use;
+ my $height = $self->getheight;
+ for my $y (0 .. $height - 1) {
+ my $colors = $self->getsamples('y' => $y, channels => [ 0 .. $channels - 1 ]);
+ while (length $colors) {
+ $color_use{ substr($colors, 0, $channels, '') }++;
+ }
+ keys %color_use > $max_colors
+ and return;
+ }
+ return \%color_use;
+}
+
+# This will return a ordered array of the colour usage. Kind of the sorted
+# version of the values of the hash returned by getcolorusagehash.
+# You might want to add safety checks and change the names, etc...
+sub getcolorusage {
+ my $self = shift;
+
+ my %opts = ( maxcolors => 2**30, @_ );
+ my $max_colors = $opts{maxcolors};
+ unless (defined $max_colors && $max_colors > 0) {
+ $self->_set_error('maxcolors must be a positive integer');
+ return;
+ }
+
+ unless (defined $self->{IMG}) {
+ $self->_set_error('empty input image');
+ return undef;
+ }
+
+ return i_get_anonymous_color_histo($self->{IMG}, $max_colors);
+}
+
# draw string to an image
sub string {
unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; }
my %input=('x'=>0, 'y'=>0, @_);
- $input{string}||=$input{text};
+ defined($input{string}) or $input{string} = $input{text};
- unless(exists $input{string}) {
+ unless(defined $input{string}) {
$self->{ERRSTR}="missing required parameter 'string'";
return;
}
}
unless ($input{font}->draw(image=>$self, %input)) {
- $self->{ERRSTR} = $self->_error_as_msg();
return;
}
return $self;
}
+sub align_string {
+ my $self = shift;
+
+ my $img;
+ if (ref $self) {
+ unless ($self->{IMG}) {
+ $self->{ERRSTR}='empty input image';
+ return;
+ }
+ $img = $self;
+ }
+ else {
+ $img = undef;
+ }
+
+ my %input=('x'=>0, 'y'=>0, @_);
+ defined $input{string}
+ or $input{string} = $input{text};
+
+ unless(exists $input{string}) {
+ $self->_set_error("missing required parameter 'string'");
+ return;
+ }
+
+ unless($input{font}) {
+ $self->_set_error("missing required parameter 'font'");
+ return;
+ }
+
+ my @result;
+ unless (@result = $input{font}->align(image=>$img, %input)) {
+ return;
+ }
+
+ return wantarray ? @result : $result[0];
+}
+
+my @file_limit_names = qw/width height bytes/;
+
+sub set_file_limits {
+ shift;
+
+ my %opts = @_;
+ my %values;
+
+ if ($opts{reset}) {
+ @values{@file_limit_names} = (0) x @file_limit_names;
+ }
+ else {
+ @values{@file_limit_names} = i_get_image_file_limits();
+ }
+
+ for my $key (keys %values) {
+ defined $opts{$key} and $values{$key} = $opts{$key};
+ }
+
+ i_set_image_file_limits($values{width}, $values{height}, $values{bytes});
+}
+
+sub get_file_limits {
+ i_get_image_file_limits();
+}
+
# Shortcuts that can be exported
sub newcolor { Imager::Color->new(@_); }
sub newfont { Imager::Font->new(@_); }
+sub NCF {
+ require Imager::Color::Float;
+ return Imager::Color::Float->new(@_);
+}
*NC=*newcolour=*newcolor;
*NF=*newfont;
return 'png' if ($ext eq "png");
return 'bmp' if ($ext eq "bmp" || $ext eq "dib");
return 'tga' if ($ext eq "tga");
- return 'rgb' if ($ext eq "rgb");
+ return 'sgi' if ($ext eq "rgb" || $ext eq "bw" || $ext eq "sgi" || $ext eq "rgba");
return 'gif' if ($ext eq "gif");
return 'raw' if ($ext eq "raw");
+ return lc $ext; # best guess
return ();
}
+sub combines {
+ return @combine_types;
+}
+
# get the minimum of a list
-sub min {
+sub _min {
my $mx=shift;
for(@_) { if ($_<$mx) { $mx=$_; }}
return $mx;
# get the maximum of a list
-sub max {
+sub _max {
my $mx=shift;
for(@_) { if ($_>$mx) { $mx=$_; }}
return $mx;
# string stuff for iptc headers
-sub clean {
+sub _clean {
my($str)=$_[0];
$str = substr($str,3);
$str =~ s/[\n\r]//g;
my $str=$self->{IPTCRAW};
- #print $str;
+ defined $str
+ or return;
@ar=split(/8BIM/,$str);
@sar=split(/\034\002/);
foreach $item (@sar) {
if ($item =~ m/^x/) {
- $caption=&clean($item);
+ $caption = _clean($item);
$i++;
}
if ($item =~ m/^P/) {
- $photogr=&clean($item);
+ $photogr = _clean($item);
$i++;
}
if ($item =~ m/^i/) {
- $headln=&clean($item);
+ $headln = _clean($item);
$i++;
}
if ($item =~ m/^n/) {
- $credit=&clean($item);
+ $credit = _clean($item);
$i++;
}
}
return (caption=>$caption,photogr=>$photogr,headln=>$headln,credit=>$credit);
}
-# Autoload methods go after =cut, and are processed by the autosplit program.
+sub Inline {
+ my ($lang) = @_;
+
+ $lang eq 'C'
+ or die "Only C language supported";
+
+ require Imager::ExtUtils;
+ return Imager::ExtUtils->inline_config;
+}
+
+# threads shouldn't try to close raw Imager objects
+sub Imager::ImgRaw::CLONE_SKIP { 1 }
+
+# backward compatibility for %formats
+package Imager::FORMATS;
+use strict;
+use constant IX_FORMATS => 0;
+use constant IX_LIST => 1;
+use constant IX_INDEX => 2;
+use constant IX_CLASSES => 3;
+
+sub TIEHASH {
+ my ($class, $formats, $classes) = @_;
+
+ return bless [ $formats, [ ], 0, $classes ], $class;
+}
+
+sub _check {
+ my ($self, $key) = @_;
+
+ (my $file = $self->[IX_CLASSES]{$key} . ".pm") =~ s(::)(/)g;
+ my $value;
+ if (eval { require $file; 1 }) {
+ $value = 1;
+ }
+ else {
+ $value = undef;
+ }
+ $self->[IX_FORMATS]{$key} = $value;
+
+ return $value;
+}
+
+sub FETCH {
+ my ($self, $key) = @_;
+
+ exists $self->[IX_FORMATS]{$key} and return $self->[IX_FORMATS]{$key};
+
+ $self->[IX_CLASSES]{$key} or return undef;
+
+ return $self->_check($key);
+}
+
+sub STORE {
+ die "%Imager::formats is not user monifiable";
+}
+
+sub DELETE {
+ die "%Imager::formats is not user monifiable";
+}
+
+sub CLEAR {
+ die "%Imager::formats is not user monifiable";
+}
+
+sub EXISTS {
+ my ($self, $key) = @_;
+
+ if (exists $self->[IX_FORMATS]{$key}) {
+ my $value = $self->[IX_FORMATS]{$key}
+ or return;
+ return 1;
+ }
+
+ $self->_check($key) or return 1==0;
+
+ return 1==1;
+}
+
+sub FIRSTKEY {
+ my ($self) = @_;
+
+ unless (@{$self->[IX_LIST]}) {
+ # full populate it
+ @{$self->[IX_LIST]} = grep $self->[IX_FORMATS]{$_},
+ keys %{$self->[IX_FORMATS]};
+
+ for my $key (keys %{$self->[IX_CLASSES]}) {
+ $self->[IX_FORMATS]{$key} and next;
+ $self->_check($key)
+ and push @{$self->[IX_LIST]}, $key;
+ }
+ }
+
+ @{$self->[IX_LIST]} or return;
+ $self->[IX_INDEX] = 1;
+ return $self->[IX_LIST][0];
+}
+
+sub NEXTKEY {
+ my ($self) = @_;
+
+ $self->[IX_INDEX] < @{$self->[IX_LIST]}
+ or return;
+
+ return $self->[IX_LIST][$self->[IX_INDEX]++];
+}
+
+sub SCALAR {
+ my ($self) = @_;
+
+ return scalar @{$self->[IX_LIST]};
+}
1;
__END__
my $format;
- my $img = Imager->new();
- $img->open(file=>$file) or die $img->errstr();
+ # see Imager::Files for information on the read() method
+ my $img = Imager->new(file=>$file)
+ or die Imager->errstr();
$file =~ s/\.[^.]*$//;
# Create smaller version
+ # documented in Imager::Transformations
my $thumb = $img->scale(scalefactor=>.3);
# Autostretch individual channels
# try to save in one of these formats
SAVE:
- for $format ( qw( png gif jpg tiff ppm ) ) {
+ for $format ( qw( png gif jpeg tiff ppm ) ) {
# Check if given format is supported
if ($Imager::formats{$format}) {
$file.="_low.$format";
print "Storing image as: $file\n";
+ # documented in Imager::Files
$thumb->write(file=>$file) or
die $thumb->errstr;
last SAVE;
}
}
-
-
-
=head1 DESCRIPTION
Imager is a module for creating and altering images. It can read and
=over
-=item Imager
+=item *
+
+Imager - This document - Synopsis, Example, Table of Contents and
+Overview.
-This document - Synopsis Example, Table of Contents and Overview.
+=item *
-=item Imager::ImageTypes
+L<Imager::Tutorial> - a brief introduction to Imager.
-Direct type/virtual images, RGB(A)/paletted images, 8/16/double
-bits/channel, color maps, channel masks, image tags, color
+=item *
+
+L<Imager::Cookbook> - how to do various things with Imager.
+
+=item *
+
+L<Imager::ImageTypes> - Basics of constructing image objects with
+C<new()>: Direct type/virtual images, RGB(A)/paletted images,
+8/16/double bits/channel, color maps, channel masks, image tags, color
quantization. Also discusses basic image information methods.
-=item Imager::Files
+=item *
-IO interaction, reading/writing images, format specific tags.
+L<Imager::Files> - IO interaction, reading/writing images, format
+specific tags.
-=item Imager::Draw
+=item *
-Drawing Primitives, lines, boxes, circles, arcs, flood fill.
+L<Imager::Draw> - Drawing Primitives, lines, boxes, circles, arcs,
+flood fill.
-=item Imager::Color
+=item *
-Color specification.
+L<Imager::Color> - Color specification.
-=item Imager::Fill
+=item *
-Fill pattern specification.
+L<Imager::Fill> - Fill pattern specification.
-=item Imager::Font
+=item *
-General font rendering, bounding boxes and font metrics.
+L<Imager::Font> - General font rendering, bounding boxes and font
+metrics.
-=item Imager::Transformations
+=item *
-Copying, scaling, cropping, flipping, blending, pasting, convert and
-map.
+L<Imager::Transformations> - Copying, scaling, cropping, flipping,
+blending, pasting, convert and map.
-=item Imager::Engines
+=item *
-Programmable transformations through C<transform()>, C<transform2()>
-and C<matrix_transform()>.
+L<Imager::Engines> - Programmable transformations through
+C<transform()>, C<transform2()> and C<matrix_transform()>.
-=item Imager::Filters
+=item *
-Filters, sharpen, blur, noise, convolve etc. and filter plugins.
+L<Imager::Filters> - Filters, sharpen, blur, noise, convolve etc. and
+filter plug-ins.
-=item Imager::Expr
+=item *
-Expressions for evaluation engine used by transform2().
+L<Imager::Expr> - Expressions for evaluation engine used by
+transform2().
-=item Imager::Matrix2d
+=item *
-Helper class for affine transformations.
+L<Imager::Matrix2d> - Helper class for affine transformations.
-=item Imager::Fountain
+=item *
-Helper for making gradient profiles.
+L<Imager::Fountain> - Helper for making gradient profiles.
-=back
+=item *
+
+L<Imager::API> - using Imager's C API
+
+=item *
+L<Imager::APIRef> - API function reference
+=item *
+
+L<Imager::Inline> - using Imager's C API from Inline::C
+
+=item *
+
+L<Imager::ExtUtils> - tools to get access to Imager's C API.
+
+=back
=head2 Basic Overview
Examples:
$img=Imager->new(); # create empty image
- $img->open(file=>'lena.png',type=>'png') or # read image from file
+ $img->read(file=>'lena.png',type=>'png') or # read image from file
die $img->errstr(); # give an explanation
# if something failed
This example creates a completely black image of width 400 and height
300 and 4 channels.
-When an operation fails which can be directly associated with an image
-the error message is stored can be retrieved with
-C<$img-E<gt>errstr()>.
+=head1 ERROR HANDLING
+
+In general a method will return false when it fails, if it does use
+the C<errstr()> method to find out why:
+
+=over
+
+=item C<errstr>
+
+Returns the last error message in that context.
+
+If the last error you received was from calling an object method, such
+as read, call errstr() as an object method to find out why:
+
+ my $image = Imager->new;
+ $image->read(file => 'somefile.gif')
+ or die $image->errstr;
+
+If it was a class method then call errstr() as a class method:
+
+ my @imgs = Imager->read_multi(file => 'somefile.gif')
+ or die Imager->errstr;
+
+Note that in some cases object methods are implemented in terms of
+class methods so a failing object method may set both.
+
+=back
+
+The C<Imager-E<gt>new> method is described in detail in
+L<Imager::ImageTypes>.
+
+=head1 METHOD INDEX
+
+Where to find information on methods for Imager class objects.
+
+addcolors() - L<Imager::ImageTypes/addcolors> - add colors to a
+paletted image
+
+addtag() - L<Imager::ImageTypes/addtag> - add image tags
+
+align_string() - L<Imager::Draw/align_string> - draw text aligned on a
+point
+
+arc() - L<Imager::Draw/arc> - draw a filled arc
-In cases where no image object is associated with an operation
-C<$Imager::ERRSTR> is used to report errors not directly associated
-with an image object.
+bits() - L<Imager::ImageTypes/bits> - number of bits per sample for the
+image
+
+box() - L<Imager::Draw/box> - draw a filled or outline box.
+
+circle() - L<Imager::Draw/circle> - draw a filled circle
+
+colorcount() - L<Imager::Draw/colorcount> - the number of colors in an
+image's palette (paletted images only)
+
+combine() - L<Imager::Transformations/combine> - combine channels from one or
+more images.
+
+combines() - L<Imager::Draw/combines> - return a list of the different
+combine type keywords
+
+compose() - L<Imager::Transformations/compose> - compose one image
+over another.
+
+convert() - L<Imager::Transformations/"Color transformations"> -
+transform the color space
+
+copy() - L<Imager::Transformations/copy> - make a duplicate of an
+image
+
+crop() - L<Imager::Transformations/crop> - extract part of an image
+
+def_guess_type() - L<Imager::Files/def_guess_type> - default function
+used to guess the output file format based on the output file name
+
+deltag() - L<Imager::ImageTypes/deltag> - delete image tags
+
+difference() - L<Imager::Filters/"Image Difference"> - produce a
+difference images from two input images.
+
+errstr() - L<"Basic Overview"> - the error from the last failed
+operation.
+
+filter() - L<Imager::Filters> - image filtering
+
+findcolor() - L<Imager::ImageTypes/findcolor> - search the image
+palette, if it has one
+
+flip() - L<Imager::Transformations/flip> - flip an image, vertically,
+horizontally
+
+flood_fill() - L<Imager::Draw/flood_fill> - fill an enclosed or same
+color area
+
+getchannels() - L<Imager::ImageTypes/getchannels> - the number of
+samples per pixel for an image
+
+getcolorcount() - L<Imager::ImageTypes/getcolorcount> - the number of
+different colors used by an image (works for direct color images)
+
+getcolors() - L<Imager::ImageTypes/getcolors> - get colors from the image
+palette, if it has one
+
+getcolorusage() - L<Imager::ImageTypes/getcolorusage>
+
+getcolorusagehash() - L<Imager::ImageTypes/getcolorusagehash>
+
+get_file_limits() - L<Imager::Files/"Limiting the sizes of images you read">
+
+getheight() - L<Imager::ImageTypes/getwidth> - height of the image in
+pixels
+
+getmask() - L<Imager::ImageTypes/getmask> - write mask for the image
+
+getpixel() - L<Imager::Draw/getpixel> - retrieve one or more pixel
+colors
+
+getsamples() - L<Imager::Draw/getsamples> - retrieve samples from a
+row or partial row of pixels.
+
+getscanline() - L<Imager::Draw/getscanline> - retrieve colors for a
+row or partial row of pixels.
+
+getwidth() - L<Imager::ImageTypes/getwidth> - width of the image in
+pixels.
+
+img_set() - L<Imager::ImageTypes/img_set> - re-use an Imager object
+for a new image.
+
+init() - L<Imager::ImageTypes/init>
+
+is_bilevel() - L<Imager::ImageTypes/is_bilevel> - returns whether
+image write functions should write the image in their bilevel (blank
+and white, no gray levels) format
+
+line() - L<Imager::Draw/line> - draw an interval
+
+load_plugin() - L<Imager::Filters/load_plugin>
+
+map() - L<Imager::Transformations/"Color Mappings"> - remap color
+channel values
+
+masked() - L<Imager::ImageTypes/masked> - make a masked image
+
+matrix_transform() - L<Imager::Engines/matrix_transform>
+
+maxcolors() - L<Imager::ImageTypes/maxcolors>
+
+NC() - L<Imager::Handy/NC>
+
+NCF() - L<Imager::Handy/NCF>
+
+new() - L<Imager::ImageTypes/new>
+
+newcolor() - L<Imager::Handy/newcolor>
+
+newcolour() - L<Imager::Handy/newcolour>
+
+newfont() - L<Imager::Handy/newfont>
+
+NF() - L<Imager::Handy/NF>
+
+open() - L<Imager::Files> - an alias for read()
+
+=for stopwords IPTC
+
+parseiptc() - L<Imager::Files/parseiptc> - parse IPTC data from a JPEG
+image
+
+paste() - L<Imager::Transformations/paste> - draw an image onto an image
+
+polygon() - L<Imager::Draw/polygon>
+
+polyline() - L<Imager::Draw/polyline>
+
+read() - L<Imager::Files> - read a single image from an image file
+
+read_multi() - L<Imager::Files> - read multiple images from an image
+file
+
+read_types() - L<Imager::Files/read_types> - list image types Imager
+can read.
+
+register_filter() - L<Imager::Filters/register_filter>
+
+register_reader() - L<Imager::Files/register_reader>
+
+register_writer() - L<Imager::Files/register_writer>
+
+rotate() - L<Imager::Transformations/rotate>
+
+rubthrough() - L<Imager::Transformations/rubthrough> - draw an image onto an
+image and use the alpha channel
+
+scale() - L<Imager::Transformations/scale>
+
+scale_calculate() - L<Imager::Transformations/scale_calculate>
+
+scaleX() - L<Imager::Transformations/scaleX>
+
+scaleY() - L<Imager::Transformations/scaleY>
+
+setcolors() - L<Imager::ImageTypes/setcolors> - set palette colors in
+a paletted image
+
+set_file_limits() - L<Imager::Files/"Limiting the sizes of images you read">
+
+setmask() - L<Imager::ImageTypes/setmask>
+
+setpixel() - L<Imager::Draw/setpixel>
+
+setsamples() - L<Imager::Draw/setsamples>
+
+setscanline() - L<Imager::Draw/setscanline>
+
+settag() - L<Imager::ImageTypes/settag>
+
+string() - L<Imager::Draw/string> - draw text on an image
+
+tags() - L<Imager::ImageTypes/tags> - fetch image tags
+
+to_paletted() - L<Imager::ImageTypes/to_paletted>
+
+to_rgb16() - L<Imager::ImageTypes/to_rgb16>
+
+to_rgb8() - L<Imager::ImageTypes/to_rgb8>
+
+transform() - L<Imager::Engines/"transform">
+
+transform2() - L<Imager::Engines/"transform2">
+
+type() - L<Imager::ImageTypes/type> - type of image (direct vs paletted)
+
+unload_plugin() - L<Imager::Filters/unload_plugin>
+
+virtual() - L<Imager::ImageTypes/virtual> - whether the image has it's own
+data
+
+write() - L<Imager::Files> - write an image to a file
+
+write_multi() - L<Imager::Files> - write multiple image to an image
+file.
+
+write_types() - L<Imager::Files/read_types> - list image types Imager
+can write.
+
+=head1 CONCEPT INDEX
+
+animated GIF - L<Imager::Files/"Writing an animated GIF">
+
+aspect ratio - L<Imager::ImageTypes/i_xres>,
+L<Imager::ImageTypes/i_yres>, L<Imager::ImageTypes/i_aspect_only>
+
+blend - alpha blending one image onto another
+L<Imager::Transformations/rubthrough>
+
+blur - L<Imager::Filters/guassian>, L<Imager::Filters/conv>
+
+boxes, drawing - L<Imager::Draw/box>
+
+changes between image - L<Imager::Filters/"Image Difference">
+
+channels, combine into one image - L<Imager::Transformations/combine>
+
+color - L<Imager::Color>
+
+color names - L<Imager::Color>, L<Imager::Color::Table>
+
+combine modes - L<Imager::Draw/"Combine Types">
+
+compare images - L<Imager::Filters/"Image Difference">
+
+contrast - L<Imager::Filters/contrast>, L<Imager::Filters/autolevels>
+
+convolution - L<Imager::Filters/conv>
+
+cropping - L<Imager::Transformations/crop>
+
+CUR files - L<Imager::Files/"ICO (Microsoft Windows Icon) and CUR (Microsoft Windows Cursor)">
+
+C<diff> images - L<Imager::Filters/"Image Difference">
+
+dpi - L<Imager::ImageTypes/i_xres>,
+L<Imager::Cookbook/"Image spatial resolution">
+
+drawing boxes - L<Imager::Draw/box>
+
+drawing lines - L<Imager::Draw/line>
+
+drawing text - L<Imager::Draw/string>, L<Imager::Draw/align_string>
+
+error message - L<"ERROR HANDLING">
+
+files, font - L<Imager::Font>
+
+files, image - L<Imager::Files>
+
+filling, types of fill - L<Imager::Fill>
+
+filling, boxes - L<Imager::Draw/box>
+
+filling, flood fill - L<Imager::Draw/flood_fill>
+
+flood fill - L<Imager::Draw/flood_fill>
+
+fonts - L<Imager::Font>
+
+fonts, drawing with - L<Imager::Draw/string>,
+L<Imager::Draw/align_string>, L<Imager::Font::Wrap>
+
+fonts, metrics - L<Imager::Font/bounding_box>, L<Imager::Font::BBox>
+
+fonts, multiple master - L<Imager::Font/"MULTIPLE MASTER FONTS">
+
+fountain fill - L<Imager::Fill/"Fountain fills">,
+L<Imager::Filters/fountain>, L<Imager::Fountain>,
+L<Imager::Filters/gradgen>
+
+GIF files - L<Imager::Files/"GIF">
+
+GIF files, animated - L<Imager::File/"Writing an animated GIF">
+
+gradient fill - L<Imager::Fill/"Fountain fills">,
+L<Imager::Filters/fountain>, L<Imager::Fountain>,
+L<Imager::Filters/gradgen>
+
+gray scale, convert image to - L<Imager::Transformations/convert>
+
+guassian blur - L<Imager::Filters/guassian>
+
+hatch fills - L<Imager::Fill/"Hatched fills">
+
+ICO files - L<Imager::Files/"ICO (Microsoft Windows Icon) and CUR (Microsoft Windows Cursor)">
+
+invert image - L<Imager::Filters/hardinvert>,
+L<Imager::Filters/hardinvertall>
+
+JPEG - L<Imager::Files/"JPEG">
+
+limiting image sizes - L<Imager::Files/"Limiting the sizes of images you read">
+
+lines, drawing - L<Imager::Draw/line>
+
+matrix - L<Imager::Matrix2d>,
+L<Imager::Transformations/"Matrix Transformations">,
+L<Imager::Font/transform>
+
+metadata, image - L<Imager::ImageTypes/"Tags">
+
+mosaic - L<Imager::Filters/mosaic>
+
+noise, filter - L<Imager::Filters/noise>
+
+noise, rendered - L<Imager::Filters/turbnoise>,
+L<Imager::Filters/radnoise>
+
+paste - L<Imager::Transformations/paste>,
+L<Imager::Transformations/rubthrough>
+
+pseudo-color image - L<Imager::ImageTypes/to_paletted>,
+L<Imager::ImageTypes/new>
+
+=for stopwords posterize
+
+posterize - L<Imager::Filters/postlevels>
+
+PNG files - L<Imager::Files>, L<Imager::Files/"PNG">
+
+PNM - L<Imager::Files/"PNM (Portable aNy Map)">
+
+rectangles, drawing - L<Imager::Draw/box>
+
+resizing an image - L<Imager::Transformations/scale>,
+L<Imager::Transformations/crop>
+
+RGB (SGI) files - L<Imager::Files/"SGI (RGB, BW)">
+
+saving an image - L<Imager::Files>
+
+scaling - L<Imager::Transformations/scale>
+
+SGI files - L<Imager::Files/"SGI (RGB, BW)">
+
+sharpen - L<Imager::Filters/unsharpmask>, L<Imager::Filters/conv>
+
+size, image - L<Imager::ImageTypes/getwidth>,
+L<Imager::ImageTypes/getheight>
+
+size, text - L<Imager::Font/bounding_box>
+
+tags, image metadata - L<Imager::ImageTypes/"Tags">
+
+text, drawing - L<Imager::Draw/string>, L<Imager::Draw/align_string>,
+L<Imager::Font::Wrap>
+
+text, wrapping text in an area - L<Imager::Font::Wrap>
+
+text, measuring - L<Imager::Font/bounding_box>, L<Imager::Font::BBox>
+
+tiles, color - L<Imager::Filters/mosaic>
+
+transparent images - L<Imager::ImageTypes>,
+L<Imager::Cookbook/"Transparent PNG">
+
+=for stopwords unsharp
+
+unsharp mask - L<Imager::Filters/unsharpmask>
+
+watermark - L<Imager::Filters/watermark>
+
+writing an image to a file - L<Imager::Files>
+
+=head1 THREADS
+
+Imager doesn't support perl threads.
+
+Imager has limited code to prevent double frees if you create images,
+colors etc, and then create a thread, but has no code to prevent two
+threads entering Imager's error handling code, and none is likely to
+be added.
=head1 SUPPORT
-You can ask for help, report bugs or express your undying love for
-Imager on the Imager-devel mailing list.
+The best place to get help with Imager is the mailing list.
To subscribe send a message with C<subscribe> in the body to:
or use the form at:
- http://www.molar.is/en/lists/imager-devel/
- (annonymous is temporarily off due to spam)
+=over
+
+L<http://www.molar.is/en/lists/imager-devel/>
+
+=back
where you can also find the mailing list archive.
-If you're into IRC, you can typically find the developers in #Imager
-on irc.rhizomatic.net. As with any IRC channel, the participants
-could be occupied or asleep, so please be patient.
+You can report bugs by pointing your browser at:
+
+=over
+
+L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Imager>
+
+=back
+
+or by sending an email to:
+
+=over
+
+bug-Imager@rt.cpan.org
-=head1 BUGS
+=back
-Bugs are listed individually for relevant pod pages.
+Please remember to include the versions of Imager, perl, supporting
+libraries, and any relevant code. If you have specific images that
+cause the problems, please include those too.
+
+If you don't want to publish your email address on a mailing list you
+can use CPAN::Forum:
+
+ http://www.cpanforum.com/dist/Imager
+
+You will need to register to post.
+
+=head1 CONTRIBUTING TO IMAGER
+
+=head2 Feedback
+
+I like feedback.
+
+If you like or dislike Imager, you can add a public review of Imager
+at CPAN Ratings:
+
+ http://cpanratings.perl.org/dist/Imager
+
+=for stopwords Bitcard
+
+This requires a Bitcard account (http://www.bitcard.org).
+
+You can also send email to the maintainer below.
+
+If you send me a bug report via email, it will be copied to Request
+Tracker.
+
+=head2 Patches
+
+I accept patches, preferably against the main branch in subversion.
+You should include an explanation of the reason for why the patch is
+needed or useful.
+
+Your patch should include regression tests where possible, otherwise
+it will be delayed until I get a chance to write them.
=head1 AUTHOR
-Arnar M. Hrafnkelsson (addi@imager.perl.org) and Tony Cook
-(tony@imager.perl.org) See the README for a complete list.
+Tony Cook <tony@imager.perl.org> is the current maintainer for Imager.
-=head1 SEE ALSO
+Arnar M. Hrafnkelsson is the original author of Imager.
-perl(1), Imager::ImageTypes(3), Imager::Files(3), Imager::Draw(3),
-Imager::Color(3), Imager::Fill(3), Imager::Font(3),
-Imager::Transformations(3), Imager::Engines(3), Imager::Filters(3),
-Imager::Expr(3), Imager::Matrix2d(3), Imager::Fountain(3)
+Many others have contributed to Imager, please see the C<README> for a
+complete list.
-Affix::Infix2Postfix(3), Parse::RecDescent(3)
-http://www.eecs.umich.edu/~addi/perl/Imager/
+=head1 LICENSE
-=cut
+Imager is licensed under the same terms as perl itself.
+
+=for stopwords
+makeblendedfont Fontforge
+A test font, FT2/fontfiles/MMOne.pfb, contains a Postscript operator
+definition copyrighted by Adobe. See F<adobe.txt> in the source for
+license information.
+=head1 SEE ALSO
+
+L<perl>(1), L<Imager::ImageTypes>(3), L<Imager::Files>(3),
+L<Imager::Draw>(3), L<Imager::Color>(3), L<Imager::Fill>(3),
+L<Imager::Font>(3), L<Imager::Transformations>(3),
+L<Imager::Engines>(3), L<Imager::Filters>(3), L<Imager::Expr>(3),
+L<Imager::Matrix2d>(3), L<Imager::Fountain>(3)
+
+L<http://imager.perl.org/>
+L<Affix::Infix2Postfix>(3), L<Parse::RecDescent>(3)
+Other perl imaging modules include:
+
+L<GD>(3), L<Image::Magick>(3), L<Graphics::Magick>(3).
+
+=cut