Imager

 view release on metacpan or  search on metacpan

Imager.pm  view on Meta::CPAN

package Imager;
use 5.006;

use strict;
use Scalar::Util;
use Imager::Color;
use Imager::Color::Float;
use Imager::Font;
use Imager::TrimColorList;
use POSIX qw(INT_MIN INT_MAX);
use if $] >= 5.014, "warnings::register" => qw(tagcodes channelmask);

our $ERRSTR;

our @EXPORT_OK = qw(
		init
		init_log
		DSO_open
		DSO_close
		DSO_funclist
		DSO_call

		load_plugin
		unload_plugin

		i_list_formats

		i_color_new
		i_color_set
		i_color_info

		i_img_info

		i_img_setmask
		i_img_getmask

		i_line
		i_line_aa
		i_box
		i_box_filled
		i_arc
		i_circle_aa

		i_bezier_multi
		i_poly_aa
		i_poly_aa_cfill

		i_copyto
		i_rubthru
		i_scaleaxis
		i_scale_nn
		i_haar
		i_count_colors

		i_gaussian
		i_conv

		i_convert
		i_map

		i_img_diff

		i_tt_set_aa
		i_tt_cp
		i_tt_text
		i_tt_bbox

		i_readpnm_wiol
		i_writeppm_wiol

		i_readraw_wiol
		i_writeraw_wiol

		i_contrast
		i_hardinvert
		i_noise
		i_bumpmap
		i_postlevels
		i_mosaic
		i_watermark

		malloc_state

		list_formats

		i_gifquant

		newfont
		newcolor
		newcolour
		NC
		NF
                NCF
);

Imager.pm  view on Meta::CPAN

    or return;

  return i_img_get_height($self->{IMG});
}

# Get number of channels in an image

sub getchannels {
  my $self = shift;

  $self->_valid_image("getchannels")
    or return;

  return i_img_getchannels($self->{IMG});
}

my @model_names = qw(unknown gray graya rgb rgba);

sub colormodel {
  my ($self, %opts) = @_;

  $self->_valid_image("colormodel")
    or return;

  my $model = i_img_color_model($self->{IMG});

  return $opts{numeric} ? $model : $model_names[$model];
}

sub colorchannels {
  my ($self) = @_;

  $self->_valid_image("colorchannels")
    or return;

  return i_img_color_channels($self->{IMG});
}

sub alphachannel {
  my ($self) = @_;

  $self->_valid_image("alphachannel")
    or return;

  return scalar(i_img_alpha_channel($self->{IMG}));
}

# Get channel mask

sub getmask {
  my $self = shift;

  $self->_valid_image("getmask")
    or return;

  return i_img_getmask($self->{IMG});
}

# Set channel mask

sub setmask {
  my $self = shift;
  my %opts = @_;

  warnings::warnif("Imager::channelmask", "setmask: image channel masks are deprecated")
      if $] >= 5.014;

  $self->_valid_image("setmask")
    or return;

  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

sub getcolorcount {
  my $self=shift;
  my %opts=('maxcolors'=>2**30,@_);

  $self->_valid_image("getcolorcount")
    or return;

  my $rc=i_count_colors($self->{IMG},$opts{'maxcolors'});
  return ($rc==-1? undef : $rc);
}

# Returns a reference to a hash. The keys are colour named (packed) and the
# values are the number of pixels in this colour.
sub getcolorusagehash {
  my $self = shift;

  $self->_valid_image("getcolorusagehash")
    or return;

  my %opts = ( maxcolors => 2**30, @_ );
  my $max_colors = $opts{maxcolors};
  unless (defined $max_colors && $max_colors > 0) {
    $self->_set_error('maxcolors must be a positive integer');
    return;
  }

  my $channels= $self->getchannels;
  # We don't want to look at the alpha channel, because some gifs using it
  # doesn't define it for every colour (but only for some)
  $channels -= 1 if $channels == 2 or $channels == 4;
  my %color_use;
  my $height = $self->getheight;
  for my $y (0 .. $height - 1) {
    my $colors = $self->getsamples('y' => $y, channels => [ 0 .. $channels - 1 ]);
    while (length $colors) {
      $color_use{ substr($colors, 0, $channels, '') }++;
    }
    keys %color_use > $max_colors
      and return;
  }
  return \%color_use;
}

# This will return a ordered array of the colour usage. Kind of the sorted
# version of the values of the hash returned by getcolorusagehash.
# You might want to add safety checks and change the names, etc...
sub getcolorusage {
  my $self = shift;

  $self->_valid_image("getcolorusage")
    or return;

  my %opts = ( maxcolors => 2**30, @_ );
  my $max_colors = $opts{maxcolors};

Imager.pm  view on Meta::CPAN


newfont() - L<Imager::Handy/newfont()>

NF() - L<Imager::Handy/NF()>

open() - L<Imager::Files/read()> - an alias for read()

open_log() - L<Imager::ImageTypes/open_log()> - open the debug log.

=for stopwords IPTC

parseiptc() - L<Imager::Files/parseiptc()> - parse IPTC data from a JPEG
image

paste() - L<Imager::Transformations/paste()> - draw an image onto an
image

polygon() - L<Imager::Draw/polygon()>

polyline() - L<Imager::Draw/polyline()>

polypolygon() - L<Imager::Draw/polypolygon()>

preload() - L<Imager::Files/preload()>

read() - L<Imager::Files/read()> - read a single image from an image file

read_multi() - L<Imager::Files/read_multi()> - read multiple images from an image
file

read_types() - L<Imager::Files/read_types()> - list image types Imager
can read.

register_filter() - L<Imager::Filters/register_filter()>

register_reader() - L<Imager::Files/register_reader()>

register_writer() - L<Imager::Files/register_writer()>

rgb_difference() - L<Imager::Filters/rgb_difference()> - produce a difference
images from two input images.

rotate() - L<Imager::Transformations/rotate()>

rubthrough() - L<Imager::Transformations/rubthrough()> - draw an image
onto an image and use the alpha channel

scale() - L<Imager::Transformations/scale()>

scale_calculate() - L<Imager::Transformations/scale_calculate()>

scaleX() - L<Imager::Transformations/scaleX()>

scaleY() - L<Imager::Transformations/scaleY()>

setcolors() - L<Imager::ImageTypes/setcolors()> - set palette colors
in a paletted image

set_file_limits() - L<Imager::Files/set_file_limits()>

setmask() - L<Imager::ImageTypes/setmask()>

setpixel() - L<Imager::Draw/setpixel()>

setsamples() - L<Imager::Draw/setsamples()>

setscanline() - L<Imager::Draw/setscanline()>

settag() - L<Imager::ImageTypes/settag()>

string() - L<Imager::Draw/string()> - draw text on an image

tags() -  L<Imager::ImageTypes/tags()> - fetch image tags

to_paletted() -  L<Imager::ImageTypes/to_paletted()>

to_rgb16() - L<Imager::ImageTypes/to_rgb16()>

to_rgb8() - L<Imager::ImageTypes/to_rgb8()>

to_rgb_double() - L<Imager::ImageTypes/to_rgb_double()> - convert to
double per sample image.

transform() - L<Imager::Engines/"transform()">

transform2() - L<Imager::Engines/"transform2()">

trim() - L<Imager::Transformations/trim()> - return a cropped image
based on border transparency or border colors.

trim_rect() - L<Imager::Transformations/trim_rect()> - return how much
trim() would remove.

type() -  L<Imager::ImageTypes/type()> - type of image (direct vs paletted)

unload_plugin() - L<Imager::Filters/unload_plugin()>

virtual() - L<Imager::ImageTypes/virtual()> - whether the image has it's own
data

write() - L<Imager::Files/write()> - write an image to a file

write_multi() - L<Imager::Files/write_multi()> - write multiple image to an image
file.

write_types() - L<Imager::Files/read_types()> - list image types Imager
can write.

=head1 CONCEPT INDEX

animated GIF - L<Imager::Files/"Writing an animated GIF">

aspect ratio - C<i_xres>, C<i_yres>, C<i_aspect_only> in
L<Imager::ImageTypes/"Common Tags">.

blend - alpha blending one image onto another
L<Imager::Transformations/rubthrough()>

blur - L<< Imager::Filters/C<gaussian> >>, L<< Imager::Filters/C<conv> >>

boxes, drawing - L<Imager::Draw/box()>



( run in 4.224 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )