Imager

 view release on metacpan or  search on metacpan

lib/Imager/ImageTypes.pod  view on Meta::CPAN


In list context returns a list:

  ($is_bilevel, $zero_is_white) = $img->is_bilevel;

An image is considered bi-level, if all of the following are true:

=over

=item *

the image is a paletted image

=item *

the image has 1 or 3 channels

=item *

the image has only 2 colors in the palette

=item *

those 2 colors are black and white, in either order.

=back

If a real bi-level organization image is ever added to Imager, this
function will return true for that too.

Returns an empty list if the image object is not initialized.

=back

=head2 Direct Type Images

Direct images store the color value directly for each pixel in the
image.

=over

=item getmask()

  @rgbanames = qw( red green blue alpha );
  my $mask = $img->getmask();
  print "Modifiable channels:\n";
  for (0..$img->getchannels()-1) {
    print $rgbanames[$_],"\n" if $mask & 1<<$_;
  }

=for stopwords th

C<getmask()> is used to fetch the current channel mask.  The mask
determines what channels are currently modifiable in the image.  The
channel mask is an integer value, if the C<i-th> least significant bit
is set the C<i-th> channel is modifiable.  eg. a channel mask of 0x5
means only channels 0 and 2 are writable.

Channel masks are deprecated.

=item setmask()

  $mask = $img->getmask();
  $img->setmask(mask=>8);     # modify alpha only

    ...

  $img->setmask(mask=>$mask); # restore previous mask

C<setmask()> is used to set the channel mask of the image.  See
L</getmask()> for details.

Channel masks are deprecated.

=back

=head2 Palette Type Images

Paletted images keep an array of up to 256 colors, and each pixel is
stored as an index into that array.

In general you can work with paletted images in the same way as RGB
images, except that if you attempt to draw to a paletted image with a
color that is not in the image's palette, the image will be converted
to an RGB image.  This means that drawing on a paletted image with
anti-aliasing enabled will almost certainly convert the image to RGB.

Palette management takes place through C<addcolors()>, C<setcolors()>,
C<getcolors()> and C<findcolor()>:

=over

=item addcolors()

You can add colors to a paletted image with the addcolors() method:

   my @colors = ( Imager::Color->new(255, 0, 0), 
                  Imager::Color->new(0, 255, 0) );
   my $index = $img->addcolors(colors=>\@colors);

The return value is the index of the first color added, or undef if
adding the colors would overflow the palette.

The only parameter is C<colors> which must be a reference to an array
of Imager::Color objects.

=item setcolors()

  $img->setcolors(start=>$start, colors=>\@colors);

Once you have colors in the palette you can overwrite them with the
C<setcolors()> method:  C<setcolors()> returns true on success.

Parameters:

=over

=item *

start - the first index to be set.  Default: 0

=item *

colors - reference to an array of Imager::Color objects.

=back

=item getcolors()

To retrieve existing colors from the palette use the getcolors() method:



( run in 0.604 second using v1.01-cache-2.11-cpan-99c4e6809bf )