package Imager;
use strict;
-use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS %formats $DEBUG %filters %DSOs $ERRSTR $fontstate %OPCODES $I2P $FORMATGUESS);
+use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS %formats $DEBUG %filters %DSOs $ERRSTR $fontstate %OPCODES $I2P $FORMATGUESS $warn_obsolete);
use IO::File;
use Imager::Color;
i_img_setmask
i_img_getmask
- i_draw
+ i_line
i_line_aa
i_box
i_box_filled
BEGIN {
require Exporter;
- require DynaLoader;
-
- $VERSION = '0.39';
- @ISA = qw(Exporter DynaLoader);
- bootstrap Imager $VERSION;
+ @ISA = qw(Exporter);
+ $VERSION = '0.47';
+ eval {
+ require XSLoader;
+ XSLoader::load(Imager => $VERSION);
+ 1;
+ } or do {
+ require DynaLoader;
+ push @ISA, 'DynaLoader';
+ bootstrap Imager $VERSION;
+ }
}
BEGIN {
callsub => sub { my %hsh=@_; i_conv($hsh{image},$hsh{coef}); }
};
- $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'],
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);
},
};
$filters{unsharpmask} =
};
$FORMATGUESS=\&def_guess_type;
+
+ $warn_obsolete = 1;
}
#
# print Dumper(@_);
#}
+sub init_log {
+ m_init_log($_[0],$_[1]);
+ log_entry("Imager $VERSION starting\n", 1);
+}
+
+
sub init {
my %parms=(loglevel=>1,@_);
if ($parms{'log'}) {
init_log($parms{'log'},$parms{'loglevel'});
}
+ if (exists $parms{'warn_obsolete'}) {
+ $warn_obsolete = $parms{'warn_obsolete'};
+ }
+
# if ($parms{T1LIB_CONFIG}) { $ENV{T1LIB_CONFIG}=$parms{T1LIB_CONFIG}; }
# if ( $ENV{T1LIB_CONFIG} and ( $fontstate eq 'missing conf' )) {
# i_init_fonts();
# $fontstate='ok';
# }
+ if (exists $parms{'t1log'}) {
+ i_init_fonts($parms{'t1log'});
+ }
}
END {
sub _color {
my $arg = shift;
+ # perl 5.6.0 seems to do weird things to $arg if we don't make an
+ # explicitly stringified copy
+ # I vaguely remember a bug on this on p5p, but couldn't find it
+ # through bugs.perl.org (I had trouble getting it to find any bugs)
+ my $copy = $arg . "";
my $result;
if (ref $arg) {
$result = $arg;
}
else {
- if ($arg =~ /^HASH\(/) {
+ if ($copy =~ /^HASH\(/) {
$result = Imager::Color->new(%$arg);
}
- elsif ($arg =~ /^ARRAY\(/) {
+ elsif ($copy =~ /^ARRAY\(/) {
if (grep $_ > 1, @$arg) {
$result = Imager::Color->new(@$arg);
}
$self->{ERRSTR}=undef; #
$self->{DEBUG}=$DEBUG;
$self->{DEBUG} && print "Initialized Imager\n";
- if ($hsh{xsize} && $hsh{ysize}) { $self->img_set(%hsh); }
+ if (defined $hsh{xsize} && defined $hsh{ysize}) {
+ unless ($self->img_set(%hsh)) {
+ $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_maxx}) {
+ $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 > $r 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;
- }
- if ($hsh{'height'}) {
- $b=int(0.5+($h-$hsh{'height'})/2);
- $t=$h+$hsh{'height'};
- } else {
- $hsh{'height'}=$b-$t;
- }
+ $l < 0 and $l = 0;
+ $r > $self->getwidth and $r = $self->getwidth;
+ $t < 0 and $t = 0;
+ $b > $self->getheight and $b = $self->getheight;
-# print "l=$l, r=$r, h=$hsh{'width'}\n";
-# print "t=$t, b=$b, w=$hsh{'height'}\n";
+ if ($l == $r || $t == $b) {
+ $self->_set_error("resulting image would have no content");
+ return;
+ }
- 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
$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 cropped image at $caller[1] line $caller[2]\n";
+ return;
+ }
+
if ($self->{IMG}) {
$result = Imager->new;
$result->{IMG} = i_img_to_rgb($self->{IMG})
}
}
-my @needseekcb = qw/tiff/;
-my %needseekcb = map { $_, $_ } @needseekcb;
+sub settag {
+ my ($self, %opts) = @_;
+
+ if ($opts{name}) {
+ $self->deltag(name=>$opts{name});
+ return $self->addtag(name=>$opts{name}, value=>$opts{value});
+ }
+ elsif (defined $opts{code}) {
+ $self->deltag(code=>$opts{code});
+ return $self->addtag(code=>$opts{code}, value=>$opts{value});
+ }
+ else {
+ return undef;
+ }
+}
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}) {
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},
$self->_set_error("Handle in fh option not opened");
return;
}
+ # flush it
+ my $oldfh = select($input->{fh});
+ # flush anything that's buffered, and make sure anything else is flushed
+ $| = 1;
+ select($oldfh);
return io_new_fd($fd);
}
elsif ($input->{file}) {
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);
- if ($iolready{$input{'type'}}) {
- # Setup data source
- my ($IO, $fh) = $self->_get_reader_io(\%input, $input{'type'})
- or return;
+ unless ($formats{$input{'type'}}) {
+ $self->_set_error("format '$input{'type'}' not supported");
+ return;
+ }
- 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;
+ # Setup data source
+ if ( $input{'type'} eq 'jpeg' ) {
+ ($self->{IMG},$self->{IPTCRAW}) = i_readjpeg_wiol( $IO );
+ if ( !defined($self->{IMG}) ) {
+ $self->{ERRSTR}=$self->_error_as_msg(); return undef;
}
+ $self->{DEBUG} && print "loading a jpeg file\n";
+ return $self;
+ }
- 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;
+ if ( $input{'type'} eq 'tiff' ) {
+ my $page = $input{'page'};
+ defined $page or $page = 0;
+ # Fixme, check if that length parameter is ever needed
+ $self->{IMG}=i_readtiff_wiol( $IO, -1, $page );
+ if ( !defined($self->{IMG}) ) {
+ $self->{ERRSTR}=$self->_error_as_msg(); return undef;
}
+ $self->{DEBUG} && print "loading a tiff file\n";
+ return $self;
+ }
- 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, -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 '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 'png' ) {
+ $self->{IMG}=i_readpng_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 png 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 '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 ($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 {
+ 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";
+ }
- # 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' ) {
+ my %params=(datachannels=>3,storechannels=>3,interleave=>1,%input);
- if (!$input{'type'}) {
- $self->{ERRSTR}='type parameter missing and not possible to guess from extension'; return undef;
+ if ( !($params{xsize} && $params{ysize}) ) {
+ $self->{ERRSTR}='missing xsize or ysize parameter for raw';
+ return undef;
}
- if (!$formats{$input{'type'}}) {
- $self->{ERRSTR}='format not supported';
+ $self->{IMG} = i_readraw_wiol( $IO,
+ $params{xsize},
+ $params{ysize},
+ $params{datachannels},
+ $params{storechannels},
+ $params{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;
- }
- binmode($fh);
- $fd = $fh->fileno();
- }
+ return $self;
+}
- if ($input{fd}) {
- $fd=$input{fd};
- }
+sub _fix_gif_positions {
+ my ($opts, $opt, $msg, @imgs) = @_;
- 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;
+ my $positions = $opts->{'gif_positions'};
+ my $index = 0;
+ for my $pos (@$positions) {
+ my ($x, $y) = @$pos;
+ my $img = $imgs[$index++];
+ $img->settag(name=>'gif_left', value=>$x);
+ $img->settag(name=>'gif_top', value=>$y) if defined $y;
+ }
+ $$msg .= "replaced with the gif_left and gif_top tags";
+}
+
+my %obsolete_opts =
+ (
+ gif_each_palette=>'gif_local_map',
+ interlace => 'gif_interlace',
+ gif_delays => 'gif_delay',
+ gif_positions => \&_fix_gif_positions,
+ gif_loop_count => 'gif_loop',
+ );
+
+sub _set_opts {
+ my ($self, $opts, $prefix, @imgs) = @_;
+
+ for my $opt (keys %$opts) {
+ my $tagname = $opt;
+ if ($obsolete_opts{$opt}) {
+ my $new = $obsolete_opts{$opt};
+ my $msg = "Obsolete option $opt ";
+ if (ref $new) {
+ $new->($opts, $opt, \$msg, @imgs);
}
- 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 )
- }
+ else {
+ $msg .= "replaced with the $new tag ";
+ $tagname = $new;
+ }
+ $msg .= "line ".(caller(2))[2]." of file ".(caller(2))[1];
+ warn $msg if $warn_obsolete && $^W;
+ }
+ next unless $tagname =~ /^\Q$prefix/;
+ my $value = $opts->{$opt};
+ if (ref $value) {
+ if (UNIVERSAL::isa($value, "Imager::Color")) {
+ my $tag = sprintf("color(%d,%d,%d,%d)", $value->rgba);
+ for my $img (@imgs) {
+ $img->settag(name=>$tagname, value=>$tag);
+ }
}
- if ($colors) {
- # we may or may not change i_readgif to return blessed objects...
- ${ $input{colors} } = [ map { NC(@$_) } @$colors ];
+ elsif (ref($value) eq 'ARRAY') {
+ for my $i (0..$#$value) {
+ my $val = $value->[$i];
+ if (ref $val) {
+ if (UNIVERSAL::isa($val, "Imager::Color")) {
+ my $tag = sprintf("color(%d,%d,%d,%d)", $value->rgba);
+ $i < @imgs and
+ $imgs[$i]->settag(name=>$tagname, value=>$tag);
+ }
+ else {
+ $self->_set_error("Unknown reference type " . ref($value) .
+ " supplied in array for $opt");
+ return;
+ }
+ }
+ else {
+ $i < @imgs
+ and $imgs[$i]->settag(name=>$tagname, value=>$val);
+ }
+ }
}
- if ( !defined($self->{IMG}) ) {
- $self->{ERRSTR}= 'reading GIF:'._error_as_msg();
- return undef;
+ else {
+ $self->_set_error("Unknown reference type " . ref($value) .
+ " supplied for $opt");
+ return;
+ }
+ }
+ else {
+ # set it as a tag for every image
+ for my $img (@imgs) {
+ $img->settag(name=>$tagname, value=>$value);
}
- $self->{DEBUG} && print "loading a gif file\n";
}
}
- return $self;
+
+ return 1;
}
# 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,
fax_fine=>1, @_);
my $rc;
- 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
+ $self->_set_opts(\%input, "i_", $self)
+ or return undef;
unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; }
my ($IO, $fh) = $self->_get_writer_io(\%input, $input{'type'})
or return undef;
- # this conditional is probably obsolete
- if ($iolready{$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;
- if ($input{'type'} eq 'tiff') {
- 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' ) {
- if ( ! i_writeppm_wiol($self->{IMG},$IO) ) {
- $self->{ERRSTR}='unable to write pnm image';
- return undef;
- }
- $self->{DEBUG} && print "writing a pnm file\n";
- } elsif ( $input{'type'} eq 'raw' ) {
- if ( !i_writeraw_wiol($self->{IMG},$IO) ) {
- $self->{ERRSTR}='unable to write raw image';
- return undef;
- }
- $self->{DEBUG} && print "writing a raw file\n";
- } elsif ( $input{'type'} eq 'png' ) {
- 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' ) {
- if ( !i_writejpeg_wiol($self->{IMG}, $IO, $input{jpegquality})) {
- $self->{ERRSTR} = $self->_error_as_msg();
+ if (defined $input{class} && $input{class} eq 'fax') {
+ if (!i_writetiff_wiol_faxable($self->{IMG}, $IO, $input{fax_fine})) {
+ $self->{ERRSTR} = $self->_error_as_msg();
return undef;
}
- $self->{DEBUG} && print "writing a jpeg file\n";
- } elsif ( $input{'type'} eq 'bmp' ) {
- if ( !i_writebmp_wiol($self->{IMG}, $IO) ) {
- $self->{ERRSTR}='unable to write bmp image';
+ } else {
+ if (!i_writetiff_wiol($self->{IMG}, $IO)) {
+ $self->{ERRSTR} = $self->_error_as_msg();
return undef;
}
- $self->{DEBUG} && print "writing a bmp file\n";
- } elsif ( $input{'type'} eq 'tga' ) {
-
- if ( !i_writetga_wiol($self->{IMG}, $IO, $input{wierdpack}, $input{compress}, $input{idstring}) ) {
- $self->{ERRSTR}=$self->_error_as_msg();
- return undef;
- }
- $self->{DEBUG} && print "writing a tga file\n";
- } elsif ( $input{'type'} eq 'gif' ) {
- # compatibility with the old interfaces
- if ($input{gifquant} eq 'lm') {
- $input{make_colors} = 'addi';
- $input{translate} = 'perturb';
- $input{perturb} = $input{lmdither};
- } elsif ($input{gifquant} eq 'gen') {
- # just pass options through
- } else {
- $input{make_colors} = 'webmap'; # ignored
- $input{translate} = 'giflib';
- }
- $rc = i_writegif_wiol($IO, \%input, $self->{IMG});
}
+ } elsif ( $input{'type'} eq 'pnm' ) {
+ $self->_set_opts(\%input, "pnm_", $self)
+ or return undef;
+ if ( ! i_writeppm_wiol($self->{IMG},$IO) ) {
+ $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} = $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;
+ $self->_set_opts(\%input, "exif_", $self)
+ or return undef;
+ if ( !i_writejpeg_wiol($self->{IMG}, $IO, $input{jpegquality})) {
+ $self->{ERRSTR} = $self->_error_as_msg();
+ 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->{DEBUG} && print "writing a bmp file\n";
+ } elsif ( $input{'type'} eq 'tga' ) {
+ $self->_set_opts(\%input, "tga_", $self)
+ or return undef;
- if (exists $input{'data'}) {
- my $data = io_slurp($IO);
- if (!$data) {
- $self->{ERRSTR}='Could not slurp from buffer';
- return undef;
- }
- ${$input{data}} = $data;
+ if ( !i_writetga_wiol($self->{IMG}, $IO, $input{wierdpack}, $input{compress}, $input{idstring}) ) {
+ $self->{ERRSTR}=$self->_error_as_msg();
+ return undef;
+ }
+ $self->{DEBUG} && print "writing a tga file\n";
+ } elsif ( $input{'type'} eq 'gif' ) {
+ $self->_set_opts(\%input, "gif_", $self)
+ or return undef;
+ # compatibility with the old interfaces
+ if ($input{gifquant} eq 'lm') {
+ $input{make_colors} = 'addi';
+ $input{translate} = 'perturb';
+ $input{perturb} = $input{lmdither};
+ } elsif ($input{gifquant} eq 'gen') {
+ # just pass options through
+ } else {
+ $input{make_colors} = 'webmap'; # ignored
+ $input{translate} = 'giflib';
+ }
+ if (!i_writegif_wiol($IO, \%input, $self->{IMG})) {
+ $self->{ERRSTR} = $self->_error_as_msg;
+ return;
}
- 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;
}
$class->_set_error('Usage: Imager->write_multi({ options }, @images)');
return 0;
}
+ $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}) {
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') {
}
}
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;
+}
+
# Scale an image to requested size and return the scaled version
sub scale {
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;
+ }
+
+ unless ($self->{IMG}) {
+ $self->_set_error('empty input image');
+ return undef;
+ }
+ # work out the scaling
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(); }
+ my ($xpix, $ypix)=( $opts{xpixels}/$self->getwidth() ,
+ $opts{ypixels}/$self->getheight() );
+ if ($opts{'type'} eq 'min') {
+ $opts{scalefactor}=min($xpix,$ypix);
+ }
+ elsif ($opts{'type'} eq 'max') {
+ $opts{scalefactor}=max($xpix,$ypix);
+ }
+ else {
+ $self->_set_error('invalid value for type parameter');
+ return undef;
+ }
+ } elsif ($opts{xpixels}) {
+ $opts{scalefactor}=$opts{xpixels}/$self->getwidth();
+ }
+ elsif ($opts{ypixels}) {
+ $opts{scalefactor}=$opts{ypixels}/$self->getheight();
+ }
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; }
+ 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; }
+ 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 'preview') {
+ $img->{IMG} = i_scale_nn($self->{IMG}, $opts{'scalefactor'},
+ $opts{'scalefactor'});
+ if ( !defined($img->{IMG}) ) {
+ $self->{ERRSTR}='unable to scale image';
+ return undef;
+ }
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
my $self=shift;
my %opts=(scalefactor=>0.5,@_);
+ 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();
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();
$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,@_);
+ 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; }
- unless (i_rubthru($self->{IMG}, $opts{src}->{IMG}, $opts{tx},$opts{ty})) {
+ %opts = (src_minx => 0,
+ src_miny => 0,
+ src_maxx => $opts{src}->getwidth(),
+ src_maxy => $opts{src}->getheight(),
+ %opts);
+
+ unless (i_rubthru($self->{IMG}, $opts{src}->{IMG}, $opts{tx}, $opts{ty},
+ $opts{src_minx}, $opts{src_miny}, $opts{src_maxx}, $opts{src_maxy})) {
$self->{ERRSTR} = $self->_error_as_msg();
return undef;
}
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) {
my $amount = $opts{radians} || $opts{degrees} * 3.1415926535 / 180;
my $result = Imager->new;
- if ($result->{IMG} = i_rotate_exact($self->{IMG}, $amount)) {
+ if ($opts{back}) {
+ $result->{IMG} = i_rotate_exact($self->{IMG}, $amount, $opts{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;
}
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; }
'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;
+ 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});
+ }
+ 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);
+ }
+ else {
+ i_arc_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);
- }
- 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);
+ my $color = _color($opts{'color'});
+ unless ($color) {
+ $self->{ERRSTR} = $Imager::ERRSTR;
+ return;
}
+ i_arc($self->{IMG},$opts{'x'},$opts{'y'},$opts{'r'},
+ $opts{'d1'}, $opts{'d2'}, $color);
}
}
return $self;
}
-# Draws a line from one point to (but not including) the destination point
+# Draws a line from one point to the other
+# the endpoint is set if the endp parameter is set which it is by default.
+# to turn of the endpoint being set use endp=>0 when calling line.
sub line {
my $self=shift;
my $dflcl=i_color_new(0,0,0,0);
- my %opts=(color=>$dflcl,@_);
+ my %opts=(color=>$dflcl,
+ endp => 1,
+ @_);
unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; }
unless (exists $opts{x1} and exists $opts{y1}) { $self->{ERRSTR}='missing begining coord'; return undef; }
unless (exists $opts{x2} and exists $opts{y2}) { $self->{ERRSTR}='missing ending coord'; return undef; }
my $color = _color($opts{'color'});
- unless ($color) {
- $self->{ERRSTR} = $Imager::ERRSTR;
- return;
+ unless ($color) {
+ $self->{ERRSTR} = $Imager::ERRSTR;
+ return;
}
+
$opts{antialias} = $opts{aa} if defined $opts{aa};
if ($opts{antialias}) {
- i_line_aa($self->{IMG},$opts{x1}, $opts{y1}, $opts{x2}, $opts{y2},
- $color);
+ i_line_aa($self->{IMG},$opts{x1}, $opts{y1}, $opts{x2}, $opts{y2},
+ $color, $opts{endp});
} else {
- i_draw($self->{IMG},$opts{x1}, $opts{y1}, $opts{x2}, $opts{y2},
- $color);
+ i_line($self->{IMG},$opts{x1}, $opts{y1}, $opts{x2}, $opts{y2},
+ $color, $opts{endp});
}
return $self;
}
if ($opts{antialias}) {
for $pt(@points) {
if (defined($ls)) {
- i_line_aa($self->{IMG},$ls->[0],$ls->[1],$pt->[0],$pt->[1],$color);
+ i_line_aa($self->{IMG},$ls->[0],$ls->[1],$pt->[0],$pt->[1],$color, 1);
}
$ls=$pt;
}
} else {
for $pt(@points) {
if (defined($ls)) {
- i_draw($self->{IMG},$ls->[0],$ls->[1],$pt->[0],$pt->[1],$color);
+ i_line($self->{IMG},$ls->[0],$ls->[1],$pt->[0],$pt->[1],$color,1);
}
$ls=$pt;
}
sub flood_fill {
my $self = shift;
my %opts = ( color=>Imager::Color->new(255, 255, 255), @_ );
+ my $rc;
unless (exists $opts{'x'} && exists $opts{'y'}) {
$self->{ERRSTR} = "missing seed x and y parameters";
return;
}
}
- i_flood_cfill($self->{IMG}, $opts{'x'}, $opts{'y'}, $opts{fill}{fill});
+ $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;
+ unless ($color) {
+ $self->{ERRSTR} = $Imager::ERRSTR;
+ 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 %opts = ( color=>$self->{fg} || NC(255, 255, 255), @_);
+
+ unless (exists $opts{'x'} && exists $opts{'y'}) {
+ $self->{ERRSTR} = 'missing x and y parameters';
+ return undef;
+ }
+
+ 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;
+ }
+ if ($color->isa('Imager::Color')) {
+ for my $i (0..$#{$opts{'x'}}) {
+ i_ppix($self->{IMG}, $x->[$i], $y->[$i], $color);
+ }
+ }
+ else {
+ for my $i (0..$#{$opts{'x'}}) {
+ i_ppixf($self->{IMG}, $x->[$i], $y->[$i], $color);
+ }
+ }
+ }
+ else {
+ if ($color->isa('Imager::Color')) {
+ i_ppix($self->{IMG}, $x, $y, $color);
+ }
+ else {
+ i_ppixf($self->{IMG}, $x, $y, $color);
}
- i_flood_fill($self->{IMG}, $opts{'x'}, $opts{'y'}, $color);
}
$self;
}
+sub getpixel {
+ my $self = shift;
+
+ my %opts = ( "type"=>'8bit', @_);
+
+ unless (exists $opts{'x'} && exists $opts{'y'}) {
+ $self->{ERRSTR} = 'missing x and y parameters';
+ return undef;
+ }
+
+ my $x = $opts{'x'};
+ my $y = $opts{'y'};
+ if (ref $x && ref $y) {
+ unless (@$x == @$y) {
+ $self->{ERRSTR} = 'length of x and y mismatch';
+ return undef;
+ }
+ my @result;
+ if ($opts{"type"} eq '8bit') {
+ for my $i (0..$#{$opts{'x'}}) {
+ push(@result, i_get_pixel($self->{IMG}, $x->[$i], $y->[$i]));
+ }
+ }
+ else {
+ for my $i (0..$#{$opts{'x'}}) {
+ push(@result, i_gpixf($self->{IMG}, $x->[$i], $y->[$i]));
+ }
+ }
+ return wantarray ? @result : \@result;
+ }
+ else {
+ if ($opts{"type"} eq '8bit') {
+ return i_get_pixel($self->{IMG}, $x, $y);
+ }
+ else {
+ return i_gpixf($self->{IMG}, $x, $y);
+ }
+ }
+
+ $self;
+}
+
+sub getscanline {
+ my $self = shift;
+ my %opts = ( type => '8bit', x=>0, @_);
+
+ 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});
+ }
+ else {
+ $self->_set_error("invalid type parameter - must be '8bit' or 'float'");
+ return;
+ }
+}
+
+sub setscanline {
+ my $self = shift;
+ my %opts = ( x=>0, @_);
+
+ 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});
+ }
+ }
+ else {
+ $self->_set_error("invalid type parameter - must be '8bit' or 'float'");
+ return;
+ }
+}
+
+sub getsamples {
+ my $self = shift;
+ my %opts = ( type => '8bit', x=>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{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}});
+ }
+ else {
+ $self->_set_error("invalid type parameter - must be '8bit' or 'float'");
+ return;
+ }
+}
+
# 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})) {
return $self;
}
+sub difference {
+ my ($self, %opts) = @_;
+
+ defined $opts{mindist} or $opts{mindist} = 0;
+
+ defined $opts{other}
+ or return $self->_set_error("No 'other' parameter supplied");
+ defined $opts{other}{IMG}
+ or return $self->_set_error("No image data in 'other' image");
+
+ $self->{IMG}
+ or return $self->_set_error("No image data");
+
+ my $result = Imager->new;
+ $result->{IMG} = i_diff_image($self->{IMG}, $opts{other}{IMG},
+ $opts{mindist})
+ or return $self->_set_error($self->_error_as_msg());
+
+ return $result;
+}
+
# destructive border - image is shrunk by one pixel all around
sub border {
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
my %input=('x'=>0, 'y'=>0, @_);
$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, @_);
+ $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(@_); }
else {
$ERRSTR = $msg;
}
+ return;
}
# Default guess for the type of an image from extension
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;
+}
1;
__END__
=head1 SYNOPSIS
- use Imager;
-
- $img = Imager->new();
- $img->open(file=>'image.ppm',type=>'pnm')
- || print "failed: ",$img->{ERRSTR},"\n";
- $scaled=$img->scale(xpixels=>400,ypixels=>400);
- $scaled->write(file=>'sc_image.ppm',type=>'pnm')
- || print "failed: ",$scaled->{ERRSTR},"\n";
-
-=head1 DESCRIPTION
-
-Imager is a module for creating and altering images - It is not meant
-as a replacement or a competitor to ImageMagick or GD. Both are
-excellent packages and well supported.
-
-=head2 Overview of documentation
-
-=over
-
-=item Imager
-
-This document - Table of Contents, Example and Overview
-
-=item Imager::ImageTypes
-
-Direct type/virtual images, RGB(A)/paletted images, 8/16/double
-bits/channel, image tags, and channel masks.
+ # Thumbnail example
-=item Imager::Files
-
-IO interaction, reading/writing images, format specific tags.
-
-=item Imager::Draw
-
-Drawing Primitives, lines boxes, circles, flood fill.
-
-=item Imager::Color
-
-Color specification.
-
-=item Imager::Font
-
-General font rendering.
-
-=item Imager::Transformations
-
-Copying, scaling, cropping, flipping, blending, pasting, [convert and map.]
-
-=item Imager::Engines
-
-transform2 and matrix_transform.
-
-=item Imager::Filters
-
-Filters, sharpen, blur, noise, convolve etc. and plugins.
-
-=item Imager::Expr
-
-Expressions for evaluation engine used by transform2().
-
-=item Imager::Matrix2d
-
-Helper class for affine transformations.
-
-=item Imager::Fountain
-
-Helper for making gradient profiles.
-
-=back
-
-
-
-
-
-
-
-
-Almost all functions take the parameters in the hash fashion.
-Example:
-
- $img->open(file=>'lena.png',type=>'png');
-
-or just:
-
- $img->open(file=>'lena.png');
-
-=head2 Basic concept
-
-An Image object is created with C<$img = Imager-E<gt>new()> Should
-this fail for some reason an explanation can be found in
-C<$Imager::ERRSTR> usually error messages are stored in
-C<$img-E<gt>{ERRSTR}>, but since no object is created this is the only
-way to give back errors. C<$Imager::ERRSTR> is also used to report
-all errors not directly associated with an image object. Examples:
-
- $img=Imager->new(); # This is an empty image (size is 0 by 0)
- $img->open(file=>'lena.png',type=>'png'); # initializes from file
-
-or if you want to create an empty image:
-
- $img=Imager->new(xsize=>400,ysize=>300,channels=>4);
-
-This example creates a completely black image of width 400 and
-height 300 and 4 channels.
-
-If you have an existing image, use img_set() to change it's dimensions
-- this will destroy any existing image data:
+ #!/usr/bin/perl -w
+ use strict;
+ use Imager;
- $img->img_set(xsize=>500, ysize=>500, channels=>4);
+ die "Usage: thumbmake.pl filename\n" if !-f $ARGV[0];
+ my $file = shift;
-To create paletted images, set the 'type' parameter to 'paletted':
+ my $format;
- $img = Imager->new(xsize=>200, ysize=>200, channels=>3, type=>'paletted');
+ my $img = Imager->new();
+ # see Imager::Files for information on the read() method
+ $img->read(file=>$file) or die $img->errstr();
-which creates an image with a maxiumum of 256 colors, which you can
-change by supplying the C<maxcolors> parameter.
+ $file =~ s/\.[^.]*$//;
-You can create a new paletted image from an existing image using the
-to_paletted() method:
+ # Create smaller version
+ # documented in Imager::Transformations
+ my $thumb = $img->scale(scalefactor=>.3);
- $palimg = $img->to_paletted(\%opts)
+ # Autostretch individual channels
+ $thumb->filter(type=>'autolevels');
-where %opts contains the options specified under L<Quantization options>.
+ # try to save in one of these formats
+ SAVE:
-You can convert a paletted image (or any image) to an 8-bit/channel
-RGB image with:
+ for $format ( qw( png gif jpg 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;
+ }
+ }
- $rgbimg = $img->to_rgb8;
+=head1 DESCRIPTION
-Warning: if you draw on a paletted image with colors that aren't in
-the palette, the image will be internally converted to a normal image.
+Imager is a module for creating and altering images. It can read and
+write various image formats, draw primitive shapes like lines,and
+polygons, blend multiple images together in various ways, scale, crop,
+render text and more.
-For improved color precision you can use the bits parameter to specify
-16 bit per channel:
+=head2 Overview of documentation
- $img = Imager->new(xsize=>200, ysize=>200, channels=>3, bits=>16);
+=over
-or for even more precision:
+=item *
- $img = Imager->new(xsize=>200, ysize=>200, channels=>3, bits=>'double');
+Imager - This document - Synopsis Example, Table of Contents and
+Overview.
-to get an image that uses a double for each channel.
+=item *
-Note that as of this writing all functions should work on images with
-more than 8-bits/channel, but many will only work at only
-8-bit/channel precision.
+L<Imager::Tutorial> - a brief introduction to Imager.
-Currently only 8-bit, 16-bit, and double per channel image types are
-available, this may change later.
+=item *
-Color objects are created by calling the Imager::Color->new()
-method:
+L<Imager::Cookbook> - how to do various things with Imager.
- $color = Imager::Color->new($red, $green, $blue);
- $color = Imager::Color->new($red, $green, $blue, $alpha);
- $color = Imager::Color->new("#C0C0FF"); # html color specification
+=item *
-This object can then be passed to functions that require a color parameter.
+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.
-Coordinates in Imager have the origin in the upper left corner. The
-horizontal coordinate increases to the right and the vertical
-downwards.
+=item *
-=head2 Reading and writing images
+L<Imager::Files> - IO interaction, reading/writing images, format
+specific tags.
-You can read and write a variety of images formats, assuming you have
-the appropriate libraries, and images can be read or written to/from
-files, file handles, file descriptors, scalars, or through callbacks.
+=item *
-To see which image formats Imager is compiled to support the following
-code snippet is sufficient:
+L<Imager::Draw> - Drawing Primitives, lines, boxes, circles, arcs,
+flood fill.
- use Imager;
- print join " ", keys %Imager::formats;
+=item *
-This will include some other information identifying libraries rather
-than file formats.
+L<Imager::Color> - Color specification.
-Reading writing to and from files is simple, use the C<read()>
-method to read an image:
+=item *
- my $img = Imager->new;
- $img->read(file=>$filename, type=>$type)
- or die "Cannot read $filename: ", $img->errstr;
+L<Imager::Fill> - Fill pattern specification.
-and the C<write()> method to write an image:
+=item *
- $img->write(file=>$filename, type=>$type)
- or die "Cannot write $filename: ", $img->errstr;
+L<Imager::Font> - General font rendering, bounding boxes and font
+metrics.
-If the I<filename> includes an extension that Imager recognizes, then
-you don't need the I<type>, but you may want to provide one anyway.
-Imager currently does not check the files magic to determine the
-format. It is possible to override the method for determining the
-filetype from the filename. If the data is given in another form than
-a file name a
+=item *
-When you read an image, Imager may set some tags, possibly including
-information about the spatial resolution, textual information, and
-animation information. See L</Tags> for specifics.
+L<Imager::Transformations> - Copying, scaling, cropping, flipping,
+blending, pasting, convert and map.
-When reading or writing you can specify one of a variety of sources or
-targets:
+=item *
-=over
+L<Imager::Engines> - Programmable transformations through
+C<transform()>, C<transform2()> and C<matrix_transform()>.
-=item file
+=item *
-The C<file> parameter is the name of the image file to be written to
-or read from. If Imager recognizes the extension of the file you do
-not need to supply a C<type>.
+L<Imager::Filters> - Filters, sharpen, blur, noise, convolve etc. and
+filter plugins.
-=item fh
+=item *
-C<fh> is a file handle, typically either returned from
-C<<IO::File->new()>>, or a glob from an C<open> call. You should call
-C<binmode> on the handle before passing it to Imager.
+L<Imager::Expr> - Expressions for evaluation engine used by
+transform2().
-=item fd
+=item *
-C<fd> is a file descriptor. You can get this by calling the
-C<fileno()> function on a file handle, or by using one of the standard
-file descriptor numbers.
+L<Imager::Matrix2d> - Helper class for affine transformations.
-=item data
+=item *
-When reading data, C<data> is a scalar containing the image file data,
-when writing, C<data> is a reference to the scalar to save the image
-file data too. For GIF images you will need giflib 4 or higher, and
-you may need to patch giflib to use this option for writing.
+L<Imager::Fountain> - Helper for making gradient profiles.
-=item callback
+=item *
-Imager will make calls back to your supplied coderefs to read, write
-and seek from/to/through the image file.
+L<Imager::API> - using Imager's C API
-When reading from a file you can use either C<callback> or C<readcb>
-to supply the read callback, and when writing C<callback> or
-C<writecb> to supply the write callback.
+=item *
-When writing you can also supply the C<maxbuffer> option to set the
-maximum amount of data that will be buffered before your write
-callback is called. Note: the amount of data supplied to your
-callback can be smaller or larger than this size.
+L<Imager::APIRef> - API function reference
-The read callback is called with 2 parameters, the minimum amount of
-data required, and the maximum amount that Imager will store in it's C
-level buffer. You may want to return the minimum if you have a slow
-data source, or the maximum if you have a fast source and want to
-prevent many calls to your perl callback. The read data should be
-returned as a scalar.
+=item *
-Your write callback takes exactly one parameter, a scalar containing
-the data to be written. Return true for success.
+L<Imager::Inline> - using Imager's C API from Inline::C
-The seek callback takes 2 parameters, a I<POSITION>, and a I<WHENCE>,
-defined in the same way as perl's seek function.
+=item *
-You can also supply a C<closecb> which is called with no parameters
-when there is no more data to be written. This could be used to flush
-buffered data.
+L<Imager::ExtUtils> - tools to get access to Imager's C API.
=back
-C<$img-E<gt>read()> generally takes two parameters, 'file' and 'type'.
-If the type of the file can be determined from the suffix of the file
-it can be omitted. Format dependant parameters are: For images of
-type 'raw' two extra parameters are needed 'xsize' and 'ysize', if the
-'channel' parameter is omitted for type 'raw' it is assumed to be 3.
-gif and png images might have a palette are converted to truecolor bit
-when read. Alpha channel is preserved for png images irregardless of
-them being in RGB or gray colorspace. Similarly grayscale jpegs are
-one channel images after reading them. For jpeg images the iptc
-header information (stored in the APP13 header) is avaliable to some
-degree. You can get the raw header with C<$img-E<gt>{IPTCRAW}>, but
-you can also retrieve the most basic information with
-C<%hsh=$img-E<gt>parseiptc()> as always patches are welcome. pnm has no
-extra options. Examples:
-
- $img = Imager->new();
- $img->read(file=>"cover.jpg") or die $img->errstr; # gets type from name
-
- $img = Imager->new();
- { local(*FH,$/); open(FH,"file.gif") or die $!; $a=<FH>; }
- $img->read(data=>$a,type=>'gif') or die $img->errstr;
-
-The second example shows how to read an image from a scalar, this is
-usefull if your data originates from somewhere else than a filesystem
-such as a database over a DBI connection.
-
-When writing to a tiff image file you can also specify the 'class'
-parameter, which can currently take a single value, "fax". If class
-is set to fax then a tiff image which should be suitable for faxing
-will be written. For the best results start with a grayscale image.
-By default the image is written at fine resolution you can override
-this by setting the "fax_fine" parameter to 0.
-
-If you are reading from a gif image file, you can supply a 'colors'
-parameter which must be a reference to a scalar. The referenced
-scalar will receive an array reference which contains the colors, each
-represented as an Imager::Color object.
-
-If you already have an open file handle, for example a socket or a
-pipe, you can specify the 'fd' parameter instead of supplying a
-filename. Please be aware that you need to use fileno() to retrieve
-the file descriptor for the file:
-
- $img->read(fd=>fileno(FILE), type=>'gif') or die $img->errstr;
-
-For writing using the 'fd' option you will probably want to set $| for
-that descriptor, since the writes to the file descriptor bypass Perl's
-(or the C libraries) buffering. Setting $| should avoid out of order
-output. For example a common idiom when writing a CGI script is:
-
- # the $| _must_ come before you send the content-type
- $| = 1;
- print "Content-Type: image/jpeg\n\n";
- $img->write(fd=>fileno(STDOUT), type=>'jpeg') or die $img->errstr;
-
-*Note that load() is now an alias for read but will be removed later*
-
-C<$img-E<gt>write> has the same interface as C<read()>. The earlier
-comments on C<read()> for autodetecting filetypes apply. For jpegs
-quality can be adjusted via the 'jpegquality' parameter (0-100). The
-number of colorplanes in gifs are set with 'gifplanes' and should be
-between 1 (2 color) and 8 (256 colors). It is also possible to choose
-between two quantizing methods with the parameter 'gifquant'. If set
-to mc it uses the mediancut algorithm from either giflibrary. If set
-to lm it uses a local means algorithm. It is then possible to give
-some extra settings. lmdither is the dither deviation amount in pixels
-(manhattan distance). lmfixed can be an array ref who holds an array
-of Imager::Color objects. Note that the local means algorithm needs
-much more cpu time but also gives considerable better results than the
-median cut algorithm.
-
-When storing targa images rle compression can be activated with the
-'compress' parameter, the 'idstring' parameter can be used to set the
-targa comment field and the 'wierdpack' option can be used to use the
-15 and 16 bit targa formats for rgb and rgba data. The 15 bit format
-has 5 of each red, green and blue. The 16 bit format in addition
-allows 1 bit of alpha. The most significant bits are used for each
-channel.
-
-Currently just for gif files, you can specify various options for the
-conversion from Imager's internal RGB format to the target's indexed
-file format. If you set the gifquant option to 'gen', you can use the
-options specified under L<Quantization options>.
-
-To see what Imager is compiled to support the following code snippet
-is sufficient:
-
- use Imager;
- print "@{[keys %Imager::formats]}";
-
-When reading raw images you need to supply the width and height of the
-image in the xsize and ysize options:
-
- $img->read(file=>'foo.raw', xsize=>100, ysize=>100)
- or die "Cannot read raw image\n";
-
-If your input file has more channels than you want, or (as is common),
-junk in the fourth channel, you can use the datachannels and
-storechannels options to control the number of channels in your input
-file and the resulting channels in your image. For example, if your
-input image uses 32-bits per pixel with red, green, blue and junk
-values for each pixel you could do:
-
- $img->read(file=>'foo.raw', xsize=>100, ysize=>100, datachannels=>4,
- storechannels=>3)
- or die "Cannot read raw image\n";
-
-Normally the raw image is expected to have the value for channel 1
-immediately following channel 0 and channel 2 immediately following
-channel 1 for each pixel. If your input image has all the channel 0
-values for the first line of the image, followed by all the channel 1
-values for the first line and so on, you can use the interleave option:
-
- $img->read(file=>'foo.raw', xsize=100, ysize=>100, interleave=>1)
- or die "Cannot read raw image\n";
-
-=head2 Multi-image files
-
-Currently just for gif files, you can create files that contain more
-than one image.
-
-To do this:
-
- Imager->write_multi(\%opts, @images)
-
-Where %opts describes 4 possible types of outputs:
-
-=over 5
-
-=item type
-
-This is C<gif> for gif animations.
-
-=item callback
-
-A code reference which is called with a single parameter, the data to
-be written. You can also specify $opts{maxbuffer} which is the
-maximum amount of data buffered. Note that there can be larger writes
-than this if the file library writes larger blocks. A smaller value
-maybe useful for writing to a socket for incremental display.
-
-=item fd
+=head2 Basic Overview
-The file descriptor to save the images to.
+An Image object is created with C<$img = Imager-E<gt>new()>.
+Examples:
-=item file
+ $img=Imager->new(); # create empty image
+ $img->read(file=>'lena.png',type=>'png') or # read image from file
+ die $img->errstr(); # give an explanation
+ # if something failed
-The name of the file to write to.
+or if you want to create an empty image:
-%opts may also include the keys from L<Gif options> and L<Quantization
-options>.
+ $img=Imager->new(xsize=>400,ysize=>300,channels=>4);
-=back
+This example creates a completely black image of width 400 and height
+300 and 4 channels.
-You must also specify the file format using the 'type' option.
+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()>.
-The current aim is to support other multiple image formats in the
-future, such as TIFF, and to support reading multiple images from a
-single file.
+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. You can also call C<Imager->errstr> to get this
+value.
-A simple example:
+The C<Imager-E<gt>new> method is described in detail in
+L<Imager::ImageTypes>.
- my @images;
- # ... code to put images in @images
- Imager->write_multi({type=>'gif',
- file=>'anim.gif',
- gif_delays=>[ (10) x @images ] },
- @images)
- or die "Oh dear!";
+=head1 METHOD INDEX
-You can read multi-image files (currently only GIF files) using the
-read_multi() method:
+Where to find information on methods for Imager class objects.
- my @imgs = Imager->read_multi(file=>'foo.gif')
- or die "Cannot read images: ",Imager->errstr;
+addcolors() - L<Imager::ImageTypes/addcolors>
-The possible parameters for read_multi() are:
+addtag() - L<Imager::ImageTypes/addtag> - add image tags
-=over
+arc() - L<Imager::Draw/arc>
-=item file
+align_string() - L<Imager::Draw/align_string>
-The name of the file to read in.
+bits() - L<Imager::ImageTypes/bits> - number of bits per sample for the
+image
-=item fh
+box() - L<Imager::Draw/box>
-A filehandle to read in. This can be the name of a filehandle, but it
-will need the package name, no attempt is currently made to adjust
-this to the caller's package.
+circle() - L<Imager::Draw/circle>
-=item fd
+colorcount() - L<Imager::Draw/colorcount>
-The numeric file descriptor of an open file (or socket).
+convert() - L<Imager::Transformations/"Color transformations"> -
+transform the color space
-=item callback
+copy() - L<Imager::Transformations/copy>
-A function to be called to read in data, eg. reading a blob from a
-database incrementally.
+crop() - L<Imager::Transformations/crop> - extract part of an image
-=item data
+deltag() - L<Imager::ImageTypes/deltag> - delete image tags
-The data of the input file in memory.
+difference() - L<Imager::Filters/"Image Difference">
-=item type
+errstr() - L<"Basic Overview">
-The type of file. If the file is parameter is given and provides
-enough information to guess the type, then this parameter is optional.
+filter() - L<Imager::Filters>
-=back
+findcolor() - L<Imager::ImageTypes/findcolor> - search the image palette, if it
+has one
-Note: you cannot use the callback or data parameter with giflib
-versions before 4.0.
+flip() - L<Imager::Transformations/flip>
-When reading from a GIF file with read_multi() the images are returned
-as paletted images.
+flood_fill() - L<Imager::Draw/flood_fill>
-=head2 Gif options
+getchannels() - L<Imager::ImageTypes/getchannels>
-These options can be specified when calling write_multi() for gif
-files, when writing a single image with the gifquant option set to
-'gen', or for direct calls to i_writegif_gen and i_writegif_callback.
+getcolorcount() - L<Imager::ImageTypes/getcolorcount>
-Note that some viewers will ignore some of these options
-(gif_user_input in particular).
+getcolors() - L<Imager::ImageTypes/getcolors> - get colors from the image
+palette, if it has one
-=over 4
+get_file_limits() - L<Imager::Files/"Limiting the sizes of images you read">
-=item gif_each_palette
+getheight() - L<Imager::ImageTypes/getwidth>
-Each image in the gif file has it's own palette if this is non-zero.
-All but the first image has a local colour table (the first uses the
-global colour table.
+getpixel() - L<Imager::Draw/getpixel>
-=item interlace
+getsamples() - L<Imager::Draw/getsamples>
-The images are written interlaced if this is non-zero.
+getscanline() - L<Imager::Draw/getscanline>
-=item gif_delays
+getwidth() - L<Imager::ImageTypes/getwidth>
-A reference to an array containing the delays between images, in 1/100
-seconds.
+img_set() - L<Imager::ImageTypes/img_set>
-If you want the same delay for every frame you can simply set this to
-the delay in 1/100 seconds.
+line() - L<Imager::Draw/line>
-=item gif_user_input
+map() - L<Imager::Transformations/"Color Mappings"> - remap color
+channel values
-A reference to an array contains user input flags. If the given flag
-is non-zero the image viewer should wait for input before displaying
-the next image.
+masked() - L<Imager::ImageTypes/masked> - make a masked image
-=item gif_disposal
+matrix_transform() - L<Imager::Engines/"Matrix Transformations">
-A reference to an array of image disposal methods. These define what
-should be done to the image before displaying the next one. These are
-integers, where 0 means unspecified, 1 means the image should be left
-in place, 2 means restore to background colour and 3 means restore to
-the previous value.
+maxcolors() - L<Imager::ImageTypes/maxcolors>
-=item gif_tran_color
+new() - L<Imager::ImageTypes/new>
-A reference to an Imager::Color object, which is the colour to use for
-the palette entry used to represent transparency in the palette. You
-need to set the transp option (see L<Quantization options>) for this
-value to be used.
+open() - L<Imager::Files> - an alias for read()
-=item gif_positions
+paste() - L<Imager::Transformations/paste> - draw an image onto an image
-A reference to an array of references to arrays which represent screen
-positions for each image.
+polygon() - L<Imager::Draw/polygon>
-=item gif_loop_count
+polyline() - L<Imager::Draw/polyline>
-If this is non-zero the Netscape loop extension block is generated,
-which makes the animation of the images repeat.
+read() - L<Imager::Files> - read a single image from an image file
-This is currently unimplemented due to some limitations in giflib.
+read_multi() - L<Imager::Files> - read multiple images from an image
+file
-=item gif_eliminate_unused
+rotate() - L<Imager::Transformations/rotate>
-If this is true, when you write a paletted image any unused colors
-will be eliminated from its palette. This is set by default.
+rubthrough() - L<Imager::Transformations/rubthrough> - draw an image onto an
+image and use the alpha channel
-=back
+scale() - L<Imager::Transformations/scale>
-=head2 Quantization options
+setscanline() - L<Imager::Draw/setscanline>
-These options can be specified when calling write_multi() for gif
-files, when writing a single image with the gifquant option set to
-'gen', or for direct calls to i_writegif_gen and i_writegif_callback.
+scaleX() - L<Imager::Transformations/scaleX>
-=over 4
+scaleY() - L<Imager::Transformations/scaleY>
-=item colors
+setcolors() - L<Imager::ImageTypes/setcolors> - set palette colors in
+a paletted image
-A arrayref of colors that are fixed. Note that some color generators
-will ignore this.
+setpixel() - L<Imager::Draw/setpixel>
-=item transp
+set_file_limits() - L<Imager::Files/"Limiting the sizes of images you read">
-The type of transparency processing to perform for images with an
-alpha channel where the output format does not have a proper alpha
-channel (eg. gif). This can be any of:
+string() - L<Imager::Draw/string> - draw text on an image
-=over 4
+tags() - L<Imager::ImageTypes/tags> - fetch image tags
-=item none
+to_paletted() - L<Imager::ImageTypes/to_paletted>
-No transparency processing is done. (default)
+to_rgb8() - L<Imager::ImageTypes/to_rgb8>
-=item threshold
+transform() - L<Imager::Engines/"transform">
-Pixels more transparent that tr_threshold are rendered as transparent.
+transform2() - L<Imager::Engines/"transform2">
-=item errdiff
+type() - L<Imager::ImageTypes/type> - type of image (direct vs paletted)
-An error diffusion dither is done on the alpha channel. Note that
-this is independent of the translation performed on the colour
-channels, so some combinations may cause undesired artifacts.
+virtual() - L<Imager::ImageTypes/virtual> - whether the image has it's own
+data
-=item ordered
+write() - L<Imager::Files> - write an image to a file
-The ordered dither specified by tr_orddith is performed on the alpha
-channel.
+write_multi() - L<Imager::Files> - write multiple image to an image
+file.
-=back
+=head1 CONCEPT INDEX
-This will only be used if the image has an alpha channel, and if there
-is space in the palette for a transparency colour.
+animated GIF - L<Imager::File/"Writing an animated GIF">
-=item tr_threshold
+aspect ratio - L<Imager::ImageTypes/i_xres>,
+L<Imager::ImageTypes/i_yres>, L<Imager::ImageTypes/i_aspect_only>
-The highest alpha value at which a pixel will be made transparent when
-transp is 'threshold'. (0-255, default 127)
+blend - alpha blending one image onto another
+L<Imager::Transformations/rubthrough>
-=item tr_errdiff
+blur - L<Imager::Filters/guassian>, L<Imager::Filters/conv>
-The type of error diffusion to perform on the alpha channel when
-transp is 'errdiff'. This can be any defined error diffusion type
-except for custom (see errdiff below).
+boxes, drawing - L<Imager::Draw/box>
-=item tr_orddith
+changes between image - L<Imager::Filter/"Image Difference">
-The type of ordered dither to perform on the alpha channel when transp
-is 'ordered'. Possible values are:
+color - L<Imager::Color>
-=over 4
+color names - L<Imager::Color>, L<Imager::Color::Table>
-=item random
+combine modes - L<Imager::Fill/combine>
-A semi-random map is used. The map is the same each time.
+compare images - L<Imager::Filter/"Image Difference">
-=item dot8
+contrast - L<Imager::Filter/contrast>, L<Imager::Filter/autolevels>
-8x8 dot dither.
+convolution - L<Imager::Filter/conv>
-=item dot4
+cropping - L<Imager::Transformations/crop>
-4x4 dot dither
+C<diff> images - L<Imager::Filter/"Image Difference">
-=item hline
+dpi - L<Imager::ImageTypes/i_xres>
-horizontal line dither.
+drawing boxes - L<Imager::Draw/box>
-=item vline
+drawing lines - L<Imager::Draw/line>
-vertical line dither.
+drawing text - L<Imager::Font/string>, L<Imager::Font/align>
-=item "/line"
+error message - L<"Basic Overview">
-=item slashline
+files, font - L<Imager::Font>
-diagonal line dither
+files, image - L<Imager::Files>
-=item '\line'
+filling, types of fill - L<Imager::Fill>
-=item backline
+filling, boxes - L<Imager::Draw/box>
-diagonal line dither
+filling, flood fill - L<Imager::Draw/flood_fill>
-=item tiny
+flood fill - L<Imager::Draw/flood_fill>
-dot matrix dither (currently the default). This is probably the best
-for displays (like web pages).
+fonts - L<Imager::Font>
-=item custom
+fonts, drawing with - L<Imager::Font/string>, L<Imager::Font/align>,
+L<Imager::Font::Wrap>
-A custom dither matrix is used - see tr_map
+fonts, metrics - L<Imager::Font/bounding_box>, L<Imager::Font::BBox>
-=back
+fonts, multiple master - L<Imager::Font/"MULTIPLE MASTER FONTS">
-=item tr_map
+fountain fill - L<Imager::Fill/"Fountain fills">,
+L<Imager::Filters/fountain>, L<Imager::Fountain>,
+L<Imager::Filters/gradgen>
-When tr_orddith is custom this defines an 8 x 8 matrix of integers
-representing the transparency threshold for pixels corresponding to
-each position. This should be a 64 element array where the first 8
-entries correspond to the first row of the matrix. Values should be
-betweern 0 and 255.
+GIF files - L<Imager::Files/"GIF">
-=item make_colors
+GIF files, animated - L<Imager::File/"Writing an animated GIF">
-Defines how the quantization engine will build the palette(s).
-Currently this is ignored if 'translate' is 'giflib', but that may
-change. Possible values are:
+gradient fill - L<Imager::Fill/"Fountain fills">,
+L<Imager::Filters/fountain>, L<Imager::Fountain>,
+L<Imager::Filters/gradgen>
-=over 4
+guassian blur - L<Imager::Filter/guassian>
-=item none
+hatch fills - L<Imager::Fill/"Hatched fills">
-Only colors supplied in 'colors' are used.
+invert image - L<Imager::Filter/hardinvert>
-=item webmap
+JPEG - L<Imager::Files/"JPEG">
-The web color map is used (need url here.)
+limiting image sizes - L<Imager::Files/"Limiting the sizes of images you read">
-=item addi
+lines, drawing - L<Imager::Draw/line>
-The original code for generating the color map (Addi's code) is used.
+matrix - L<Imager::Matrix2d>,
+L<Imager::Transformations/"Matrix Transformations">,
+L<Imager::Font/transform>
-=back
+metadata, image - L<Imager::ImageTypes/"Tags">
-Other methods may be added in the future.
+mosaic - L<Imager::Filter/mosaic>
-=item colors
+noise, filter - L<Imager::Filter/noise>
-A arrayref containing Imager::Color objects, which represents the
-starting set of colors to use in translating the images. webmap will
-ignore this. The final colors used are copied back into this array
-(which is expanded if necessary.)
+noise, rendered - L<Imager::Filter/turbnoise>,
+L<Imager::Filter/radnoise>
-=item max_colors
+paste - L<Imager::Transformations/paste>,
+L<Imager::Transformations/rubthrough>
-The maximum number of colors to use in the image.
+pseudo-color image - L<Imager::ImageTypes/to_paletted>,
+L<Imager::ImageTypes/new>
-=item translate
+posterize - L<Imager::Filter/postlevels>
-The method used to translate the RGB values in the source image into
-the colors selected by make_colors. Note that make_colors is ignored
-whene translate is 'giflib'.
+png files - L<Imager::Files>, L<Imager::Files/"PNG">
-Possible values are:
+pnm - L<Imager::Files/"PNM (Portable aNy Map)">
-=over 4
+rectangles, drawing - L<Imager::Draw/box>
-=item giflib
+resizing an image - L<Imager::Transformations/scale>,
+L<Imager::Transformations/crop>
-The giflib native quantization function is used.
+saving an image - L<Imager::Files>
-=item closest
+scaling - L<Imager::Transformations/scale>
-The closest color available is used.
+sharpen - L<Imager::Filters/unsharpmask>, L<Imager::Filters/conv>
-=item perturb
+size, image - L<Imager::ImageTypes/getwidth>,
+L<Imager::ImageTypes/getheight>
-The pixel color is modified by perturb, and the closest color is chosen.
+size, text - L<Imager::Font/bounding_box>
-=item errdiff
+tags, image metadata - L<Imager::ImageTypes/"Tags">
-An error diffusion dither is performed.
+text, drawing - L<Imager::Draw/string>, L<Imager::Draw/align_string>,
+L<Imager::Font::Wrap>
-=back
+text, wrapping text in an area - L<Imager::Font::Wrap>
-It's possible other transate values will be added.
+text, measuring - L<Imager::Font/bounding_box>, L<Imager::Font::BBox>
-=item errdiff
+tiles, color - L<Imager::Filter/mosaic>
-The type of error diffusion dither to perform. These values (except
-for custom) can also be used in tr_errdif.
+unsharp mask - L<Imager::Filter/unsharpmask>
-=over 4
+watermark - L<Imager::Filter/watermark>
-=item floyd
+writing an image to a file - L<Imager::Files>
-Floyd-Steinberg dither
+=head1 SUPPORT
-=item jarvis
+You can ask for help, report bugs or express your undying love for
+Imager on the Imager-devel mailing list.
-Jarvis, Judice and Ninke dither
+To subscribe send a message with C<subscribe> in the body to:
-=item stucki
+ imager-devel+request@molar.is
-Stucki dither
+or use the form at:
-=item custom
+=over
-Custom. If you use this you must also set errdiff_width,
-errdiff_height and errdiff_map.
+L<http://www.molar.is/en/lists/imager-devel/>
=back
-=item errdiff_width
+where you can also find the mailing list archive.
-=item errdiff_height
+If you're into IRC, you can typically find the developers in #Imager
+on irc.perl.org. As with any IRC channel, the participants could be
+occupied or asleep, so please be patient.
-=item errdiff_orig
+You can report bugs by pointing your browser at:
-=item errdiff_map
-
-When translate is 'errdiff' and errdiff is 'custom' these define a
-custom error diffusion map. errdiff_width and errdiff_height define
-the size of the map in the arrayref in errdiff_map. errdiff_orig is
-an integer which indicates the current pixel position in the top row
-of the map.
-
-=item perturb
+=over
-When translate is 'perturb' this is the magnitude of the random bias
-applied to each channel of the pixel before it is looked up in the
-color table.
+L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Imager>
=back
+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.
+=head1 BUGS
+Bugs are listed individually for relevant pod pages.
+=head1 AUTHOR
+Arnar M. Hrafnkelsson and Tony Cook (tony@imager.perl.org) among
+others. See the README for a complete list.
+=head1 SEE ALSO
-=head1 BUGS
-
-box, arc, circle do not support antialiasing yet. arc, is only filled
-as of yet. Some routines do not return $self where they should. This
-affects code like this, C<$img-E<gt>box()-E<gt>arc()> where an object
-is expected.
-
-When saving Gif images the program does NOT try to shave of extra
-colors if it is possible. If you specify 128 colors and there are
-only 2 colors used - it will have a 128 colortable anyway.
+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)
-=head1 AUTHOR
+L<http://imager.perl.org/>
-Arnar M. Hrafnkelsson, addi@umich.edu, and recently lots of assistance
-from Tony Cook. See the README for a complete list.
+L<Affix::Infix2Postfix>(3), L<Parse::RecDescent>(3)
-=head1 SEE ALSO
+Other perl imaging modules include:
-perl(1), Imager::Color(3), Imager::Font(3), Imager::Matrix2d(3),
-Affix::Infix2Postfix(3), Parse::RecDescent(3)
-http://www.eecs.umich.edu/~addi/perl/Imager/
+L<GD>(3), L<Image::Magick>(3), L<Graphics::Magick>(3).
=cut