Imager






Pair Networks
Imager

NAME

Imager - Perl extension for Generating 24 bit Images

SYNOPSIS

  # Thumbnail example

  #!/usr/bin/perl -w
  use strict;
  use Imager;

  die "Usage: thumbmake.pl filename\n" if !-f $ARGV[0];
  my $file = shift;

  my $format;

  # see Imager::Files for information on the read() method
  my $img = Imager->new(file=>$file)
    or die Imager->errstr();

  $file =~ s/\.[^.]*$//;

  # Create smaller version
  # documented in Imager::Transformations
  my $thumb = $img->scale(scalefactor=>.3);

  # Autostretch individual channels
  $thumb->filter(type=>'autolevels');

  # try to save in one of these formats
  SAVE:

  for $format ( qw( png gif jpeg tiff ppm ) ) {
    # Check if given format is supported
    if ($Imager::formats{$format}) {
      $file.="_low.$format";
      print "Storing image as: $file\n";
      # documented in Imager::Files
      $thumb->write(file=>$file) or
        die $thumb->errstr;
      last SAVE;
    }
  }

DESCRIPTION

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.

Overview of documentation

Basic Overview

An Image object is created with $img = Imager->new(). Examples:

  $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

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.

ERROR HANDLING

In general a method will return false when it fails, if it does use the errstr() method to find out why:

errstr()

Returns the last error message in that context.

If the last error you received was from calling an object method, such as read, call errstr() as an object method to find out why:

  my $image = Imager->new;
  $image->read(file => 'somefile.gif')
     or die $image->errstr;

If it was a class method then call errstr() as a class method:

  my @imgs = Imager->read_multi(file => 'somefile.gif')
    or die Imager->errstr;

Note that in some cases object methods are implemented in terms of class methods so a failing object method may set both.

The Imager->new method is described in detail in Imager::ImageTypes.

METHOD INDEX

Where to find information on methods for Imager class objects.

addcolors() - Imager::ImageTypes/addcolors() - add colors to a paletted image

addtag() - Imager::ImageTypes/addtag() - add image tags

align_string() - Imager::Draw/align_string() - draw text aligned on a point

alphachannel() - Imager::ImageTypes/alphachannel() - return the channel index of the alpha channel (if any).

arc() - Imager::Draw/arc() - draw a filled arc

bits() - Imager::ImageTypes/bits() - number of bits per sample for the image

box() - Imager::Draw/box() - draw a filled or outline box.

check_file_limits() - Imager::Files/check_file_limits()

circle() - Imager::Draw/circle() - draw a filled circle

close_log() - Imager::ImageTypes/close_log() - close the Imager debugging log.

colorchannels() - Imager::ImageTypes/colorchannels() - the number of channels used for color.

colorcount() - Imager::ImageTypes/colorcount() - the number of colors in an image's palette (paletted images only)

colormodel() - Imager::ImageTypes/colorcount() - how color is represented.

combine() - Imager::Transformations/combine() - combine channels from one or more images.

combines() - Imager::Draw/combines() - return a list of the different combine type keywords

compose() - Imager::Transformations/compose() - compose one image over another.

convert() - Imager::Transformations/convert() - transform the color space

copy() - Imager::Transformations/copy() - make a duplicate of an image

crop() - Imager::Transformations/crop() - extract part of an image

def_guess_type() - Imager::Files/def_guess_type() - default function used to guess the output file format based on the output file name

deltag() - Imager::ImageTypes/deltag() - delete image tags

difference() - Imager::Filters/difference() - produce a difference images from two input images.

errstr() - /errstr() - the error from the last failed operation.

filter() - Imager::Filters/filter() - image filtering

findcolor() - Imager::ImageTypes/findcolor() - search the image palette, if it has one

flip() - Imager::Transformations/flip() - flip an image, vertically, horizontally

flood_fill() - Imager::Draw/flood_fill() - fill an enclosed or same color area

getchannels() - Imager::ImageTypes/getchannels() - the number of samples per pixel for an image

getcolorcount() - Imager::ImageTypes/getcolorcount() - the number of different colors used by an image (works for direct color images)

getcolors() - Imager::ImageTypes/getcolors() - get colors from the image palette, if it has one

getcolorusage() - Imager::ImageTypes/getcolorusage()

getcolorusagehash() - Imager::ImageTypes/getcolorusagehash()

get_file_limits() - Imager::Files/get_file_limits()

getheight() - Imager::ImageTypes/getheight() - height of the image in pixels

getmask() - Imager::ImageTypes/getmask() - write mask for the image

getpixel() - Imager::Draw/getpixel() - retrieve one or more pixel colors

getsamples() - Imager::Draw/getsamples() - retrieve samples from a row or partial row of pixels.

getscanline() - Imager::Draw/getscanline() - retrieve colors for a row or partial row of pixels.

getwidth() - Imager::ImageTypes/getwidth() - width of the image in pixels.

img_set() - Imager::ImageTypes/img_set() - re-use an Imager object for a new image.

init() - Imager::ImageTypes/init()

is_bilevel() - Imager::ImageTypes/is_bilevel() - returns whether image write functions should write the image in their bilevel (blank and white, no gray levels) format

is_logging() Imager::ImageTypes/is_logging() - test if the debug log is active.

line() - Imager::Draw/line() - draw an interval

load_plugin() - Imager::Filters/load_plugin()

log() - Imager::ImageTypes/log() - send a message to the debugging log.

make_palette() - Imager::ImageTypes/make_palette() - produce a color palette from one or more input images.

map() - Imager::Transformations/map() - remap color channel values

masked() - Imager::ImageTypes/masked() - make a masked image

matrix_transform() - Imager::Engines/matrix_transform()

maxcolors() - Imager::ImageTypes/maxcolors()

NC() - Imager::Handy/NC()

NCF() - Imager::Handy/NCF()

new() - Imager::ImageTypes/new()

newcolor() - Imager::Handy/newcolor()

newcolour() - Imager::Handy/newcolour()

newfont() - Imager::Handy/newfont()

NF() - Imager::Handy/NF()

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

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

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

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

polygon() - Imager::Draw/polygon()

polyline() - Imager::Draw/polyline()

polypolygon() - Imager::Draw/polypolygon()

preload() - Imager::Files/preload()

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

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

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

register_filter() - Imager::Filters/register_filter()

register_reader() - Imager::Files/register_reader()

register_writer() - Imager::Files/register_writer()

rotate() - Imager::Transformations/rotate()

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

scale() - Imager::Transformations/scale()

scale_calculate() - Imager::Transformations/scale_calculate()

scaleX() - Imager::Transformations/scaleX()

scaleY() - Imager::Transformations/scaleY()

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

set_file_limits() - Imager::Files/set_file_limits()

setmask() - Imager::ImageTypes/setmask()

setpixel() - Imager::Draw/setpixel()

setsamples() - Imager::Draw/setsamples()

setscanline() - Imager::Draw/setscanline()

settag() - Imager::ImageTypes/settag()

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

tags() - Imager::ImageTypes/tags() - fetch image tags

to_paletted() - Imager::ImageTypes/to_paletted()

to_rgb16() - Imager::ImageTypes/to_rgb16()

to_rgb8() - Imager::ImageTypes/to_rgb8()

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

transform() - Imager::Engines/"transform()"

transform2() - Imager::Engines/"transform2()"

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

unload_plugin() - Imager::Filters/unload_plugin()

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

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

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

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

CONCEPT INDEX

animated GIF - Imager::Files/"Writing an animated GIF"

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

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

blur - Imager::Filters/gaussian, Imager::Filters/conv

boxes, drawing - Imager::Draw/box()

changes between image - Imager::Filters/"Image Difference"

channels, combine into one image - Imager::Transformations/combine()

color - Imager::Color

color names - Imager::Color, Imager::Color::Table

combine modes - Imager::Draw/"Combine Types"

compare images - Imager::Filters/"Image Difference"

contrast - Imager::Filters/contrast, Imager::Filters/autolevels

convolution - Imager::Filters/conv

cropping - Imager::Transformations/crop()

CUR files - Imager::Files/"ICO (Microsoft Windows Icon) and CUR (Microsoft Windows Cursor)"

diff images - Imager::Filters/"Image Difference"

dpi - i_xres, i_yres in Imager::ImageTypes/"Common Tags", Imager::Cookbook/"Image spatial resolution"

drawing boxes - Imager::Draw/box()

drawing lines - Imager::Draw/line()

drawing text - Imager::Draw/string(), Imager::Draw/align_string()

error message - /"ERROR HANDLING"

files, font - Imager::Font

files, image - Imager::Files

filling, types of fill - Imager::Fill

filling, boxes - Imager::Draw/box()

filling, flood fill - Imager::Draw/flood_fill()

flood fill - Imager::Draw/flood_fill()

fonts - Imager::Font

fonts, drawing with - Imager::Draw/string(), Imager::Draw/align_string(), Imager::Font::Wrap

fonts, metrics - Imager::Font/bounding_box(), Imager::Font::BBox

fonts, multiple master - Imager::Font/"MULTIPLE MASTER FONTS"

fountain fill - Imager::Fill/"Fountain fills", Imager::Filters/fountain, Imager::Fountain, Imager::Filters/gradgen

GIF files - Imager::Files/"GIF"

GIF files, animated - Imager::Files/"Writing an animated GIF"

gradient fill - Imager::Fill/"Fountain fills", Imager::Filters/fountain, Imager::Fountain, Imager::Filters/gradgen

gray scale, convert image to - Imager::Transformations/convert()

gaussian blur - Imager::Filters/gaussian

hatch fills - Imager::Fill/"Hatched fills"

ICO files - Imager::Files/"ICO (Microsoft Windows Icon) and CUR (Microsoft Windows Cursor)"

invert image - Imager::Filters/hardinvert, Imager::Filters/hardinvertall

JPEG - Imager::Files/"JPEG"

limiting image sizes - Imager::Files/"Limiting the sizes of images you read"

lines, drawing - Imager::Draw/line()

matrix - Imager::Matrix2d, Imager::Engines/"Matrix Transformations", Imager::Font/transform()

metadata, image - Imager::ImageTypes/"Tags", Image::ExifTool

mosaic - Imager::Filters/mosaic

noise, filter - Imager::Filters/noise

noise, rendered - Imager::Filters/turbnoise, Imager::Filters/radnoise

paste - Imager::Transformations/paste(), Imager::Transformations/rubthrough()

pseudo-color image - Imager::ImageTypes/to_paletted(), Imager::ImageTypes/new()

posterize - Imager::Filters/postlevels

PNG files - Imager::Files, Imager::Files/"PNG"

PNM - Imager::Files/"PNM (Portable aNy Map)"

rectangles, drawing - Imager::Draw/box()

resizing an image - Imager::Transformations/scale(), Imager::Transformations/crop()

RGB (SGI) files - Imager::Files/"SGI (RGB, BW)"

saving an image - Imager::Files

scaling - Imager::Transformations/scale()

security - Imager::Security

SGI files - Imager::Files/"SGI (RGB, BW)"

sharpen - Imager::Filters/unsharpmask, Imager::Filters/conv

size, image - Imager::ImageTypes/getwidth(), Imager::ImageTypes/getheight()

size, text - Imager::Font/bounding_box()

tags, image metadata - Imager::ImageTypes/"Tags"

text, drawing - Imager::Draw/string(), Imager::Draw/align_string(), Imager::Font::Wrap

text, wrapping text in an area - Imager::Font::Wrap

text, measuring - Imager::Font/bounding_box(), Imager::Font::BBox

threads - Imager::Threads

tiles, color - Imager::Filters/mosaic

transparent images - Imager::ImageTypes, Imager::Cookbook/"Transparent PNG"

unsharp mask - Imager::Filters/unsharpmask

watermark - Imager::Filters/watermark

writing an image to a file - Imager::Files

SUPPORT

The best place to get help with Imager is the mailing list.

To subscribe send a message with subscribe in the body to:

   imager-devel+request@molar.is

or use the form at:

http://www.molar.is/en/lists/imager-devel/

where you can also find the mailing list archive.

You can report bugs by pointing your browser at:

https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Imager

or by sending an email to:

bug-Imager@rt.cpan.org

Please remember to include the versions of Imager, perl, supporting libraries, and any relevant code. If you have specific images that cause the problems, please include those too.

If you don't want to publish your email address on a mailing list you can use CPAN::Forum:

  http://www.cpanforum.com/dist/Imager

You will need to register to post.

CONTRIBUTING TO IMAGER

Feedback

I like feedback.

If you like or dislike Imager, you can add a public review of Imager at CPAN Ratings:

  http://cpanratings.perl.org/dist/Imager

This requires a Bitcard account (http://www.bitcard.org).

You can also send email to the maintainer below.

If you send me a bug report via email, it will be copied to Request Tracker.

Patches

I accept patches, preferably against the master branch in git. Please include an explanation of the reason for why the patch is needed or useful.

Your patch should include regression tests where possible, otherwise it will be delayed until I get a chance to write them.

To browse Imager's git repository:

  http://git.imager.perl.org/imager.git

To clone:

  git clone git://git.imager.perl.org/imager.git

My preference is that patches are provided in the format produced by git format-patch, for example, if you made your changes in a branch from master you might do:

  git format-patch -k --stdout master >my-patch.txt

and then attach that to your bug report, either by adding it as an attachment in your email client, or by using the Request Tracker attachment mechanism.

AUTHOR

Tony Cook <tonyc@cpan.org> is the current maintainer for Imager.

Arnar M. Hrafnkelsson is the original author of Imager.

Many others have contributed to Imager, please see the README for a complete list.

LICENSE

Imager is licensed under the same terms as perl itself.

A test font, generated by the Debian packaged Fontforge, FT2/fontfiles/MMOne.pfb, contains a Postscript operator definition copyrighted by Adobe. See adobe.txt in the source for license information.

SEE ALSO

perl(1), Imager::ImageTypes(3), Imager::Files(3), Imager::Draw(3), Imager::Color(3), Imager::Fill(3), Imager::Font(3), Imager::Transformations(3), Imager::Engines(3), Imager::Filters(3), Imager::Expr(3), Imager::Matrix2d(3), Imager::Fountain(3)

http://imager.perl.org/

Affix::Infix2Postfix(3), Parse::RecDescent(3)

Other perl imaging modules include:

GD(3), Image::Magick(3), Graphics::Magick(3), Prima::Image, IPA.

For manipulating image metadata see Image::ExifTool.

If you're trying to use Imager for array processing, you should probably using PDL.