X-Git-Url: http://git.imager.perl.org/imager.git/blobdiff_plain/4f57931328ecb8d322c3244e519e9fc18f46e5bd..dc96e46cbbdfd9f0997dc12ddac6dfcf55412ff2:/Imager.pm diff --git a/Imager.pm b/Imager.pm index 159d0c80..0f684aec 100644 --- a/Imager.pm +++ b/Imager.pm @@ -146,7 +146,7 @@ use Imager::Font; BEGIN { require Exporter; @ISA = qw(Exporter); - $VERSION = '0.47'; + $VERSION = '0.48'; eval { require XSLoader; XSLoader::load(Imager => $VERSION); @@ -241,11 +241,26 @@ BEGIN { } }; - $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 => { }, @@ -372,7 +387,8 @@ BEGIN { i_fountain($hsh{image}, $hsh{xa}, $hsh{ya}, $hsh{xb}, $hsh{yb}, $hsh{ftype}, $hsh{repeat}, $hsh{combine}, $hsh{super_sample}, - $hsh{ssample_param}, \@segments); + $hsh{ssample_param}, \@segments) + or die Imager->_error_as_msg() . "\n"; }, }; $filters{unsharpmask} = @@ -1818,8 +1834,8 @@ sub scale { # 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 (defined wantarray) { my @caller = caller; @@ -1827,24 +1843,39 @@ sub scaleX { return; } - unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; } + 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; @@ -1856,16 +1887,26 @@ sub scaleY { 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 @@ -2025,8 +2066,14 @@ 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; } + 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, @@ -2035,8 +2082,9 @@ sub rubthrough { %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(); + $opts{src_minx}, $opts{src_miny}, + $opts{src_maxx}, $opts{src_maxy})) { + $self->_set_error($self->_error_as_msg()); return undef; } return $self; @@ -2091,9 +2139,16 @@ sub rotate { 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 ($opts{back}) { - $result->{IMG} = i_rotate_exact($self->{IMG}, $amount, $opts{back}); + 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); @@ -3334,7 +3389,7 @@ channel values masked() - L - make a masked image -matrix_transform() - L +matrix_transform() - L maxcolors() - L @@ -3360,8 +3415,6 @@ image and use the alpha channel scale() - L -setscanline() - L - scaleX() - L scaleY() - L @@ -3371,6 +3424,10 @@ a paletted image setpixel() - L +setscanline() - L + +settag() - L + set_file_limits() - L string() - L - draw text on an image