Imager(3pm)

πŸ’– NAME πŸ’–

okay so Imager(3pm) is the manual page for Imager β€” a Perl extension for Generating 24 bit Images. yes, capital G, capital I, icon behavior πŸ’… It’s your bestie for creating and altering images: reading and writing formats, drawing, blending, scaling, cropping, rendering text, and more.

✨ SYNOPSIS ✨

here’s the thumbnail example, no cap:

  # 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. it’s giving β€œimage toolkit but make it Perl” and honestly? obsessed 🫢

🌈 Overview of documentation 🌈

  • Imager β€” this document right here: Synopsis, Example, Table of Contents and Overview. meta much? πŸ’…
  • Imager::Install β€” installation notes for Imager.
  • Imager::Tutorial β€” a brief introduction to Imager.
  • Imager::Cookbook β€” how to do various things with Imager.
  • Imager::ImageTypes β€” Basics of constructing image objects with 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.
  • Imager::Files β€” IO interaction, reading/writing images, format specific tags.
  • Imager::Draw β€” Drawing Primitives, lines, boxes, circles, arcs, flood fill.
  • Imager::Color β€” Color specification.
  • Imager::Fill β€” Fill pattern specification.
  • Imager::Font β€” General font rendering, bounding boxes and font metrics.
  • Imager::Transformations β€” Copying, scaling, cropping, flipping, blending, pasting, convert and map.
  • Imager::Engines β€” Programmable transformations through transform(), transform2() and matrix_transform().
  • Imager::Filters β€” Filters, sharpen, blur, noise, convolve etc. and filter plug-ins.
  • Imager::Expr β€” Expressions for evaluation engine used by transform2().
  • Imager::Matrix2d β€” Helper class for affine transformations.
  • Imager::Fountain β€” Helper for making gradient profiles.
  • Imager::IO β€” Imager I/O abstraction.
  • Imager::API β€” using Imager's C API
  • Imager::APIRef β€” API function reference
  • Imager::Inline β€” using Imager's C API from Inline::C
  • Imager::ExtUtils β€” tools to get access to Imager's C API.
  • Imager::Security β€” brief security notes.
  • Imager::Threads β€” brief information on working with threads.

πŸŽ€ 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. little void-core moment, but make it fashion πŸ–€

😭 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. iykyk πŸ‘‘

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

πŸ“‡ METHOD INDEX πŸ“‡

okay bestie so this is the master map β€” every method in the Imager universe and which module's docs actually explain it. think of it as the group chat directory: you got a name, you got the module they live in, and a one-line vibe check. click through, iykyk πŸ’…

  • addcolors() β€” addcolors() in Imager::ImageTypes β€” adds colors to a paletted image
  • add_file_magic() β€” add_file_magic() in Imager::Files β€” adds magic to Imager's file type detector
  • addtag() β€” addtag() in Imager::ImageTypes β€” adds image tags
  • add_type_extensions() β€” add_file_magic() in Imager::Files β€” adds magic for new image file types
  • add_type_extensions($type, $ext, ...) β€” in Imager::Files β€” adds extensions for new image file types
  • align_string() β€” align_string() in Imager::Draw β€” draws text aligned on a point
  • alphachannel() β€” alphachannel() in Imager::ImageTypes β€” returns the channel index of the alpha channel (if any)
  • arc() β€” arc() in Imager::Draw β€” draws a filled arc
  • bits() β€” bits() in Imager::ImageTypes β€” number of bits per sample for the image
  • box() β€” box() in Imager::Draw β€” draws a filled or outline box
  • check_file_limits() β€” check_file_limits() in Imager::Files
  • circle() β€” circle() in Imager::Draw β€” draws a filled circle
  • close_log() β€” close_log() in Imager::ImageTypes β€” closes the Imager debugging log
  • colorchannels() β€” colorchannels() in Imager::ImageTypes β€” the number of channels used for color
  • colorcount() β€” colorcount() in Imager::ImageTypes β€” the number of colors in an image's palette (paletted images only)
  • colormodel() β€” colorcount() in Imager::ImageTypes β€” how color is represented
  • combine() β€” combine() in Imager::Transformations β€” combines channels from one or more images
  • combines() β€” combines() in Imager::Draw β€” returns a list of the different combine type keywords
  • compose() β€” compose() in Imager::Transformations β€” composes one image over another
  • convert() β€” convert() in Imager::Transformations β€” transforms the color space
  • copy() β€” copy() in Imager::Transformations β€” makes a duplicate of an image
  • crop() β€” crop() in Imager::Transformations β€” extracts part of an image
  • def_guess_type() β€” def_guess_type() in Imager::Files β€” the default function used to guess the output file format based on the output file name
  • deltag() β€” deltag() in Imager::ImageTypes β€” deletes image tags
  • difference() β€” difference() in Imager::Filters β€” produces a difference images from two input images
  • errstr() β€” errstr() β€” the error from the last failed operation
  • filter() β€” filter() in Imager::Filters β€” image filtering
  • findcolor() β€” findcolor() in Imager::ImageTypes β€” searches the image palette, if it has one
  • flip() β€” flip() in Imager::Transformations β€” flips an image, vertically, horizontally
  • flood_fill() β€” flood_fill() in Imager::Draw β€” fills an enclosed or same color area
  • getchannels() β€” getchannels() in Imager::ImageTypes β€” the number of samples per pixel for an image
  • getcolorcount() β€” getcolorcount() in Imager::ImageTypes β€” the number of different colors used by an image (works for direct color images)
  • getcolors() β€” getcolors() in Imager::ImageTypes β€” gets colors from the image palette, if it has one
  • getcolorusage() β€” getcolorusage() in Imager::ImageTypes
  • getcolorusagehash() β€” getcolorusagehash() in Imager::ImageTypes
  • get_file_limits() β€” get_file_limits() in Imager::Files
  • getheight() β€” getheight() in Imager::ImageTypes β€” height of the image in pixels
  • getmask() β€” getmask() in Imager::ImageTypes β€” write mask for the image
  • getpixel() β€” getpixel() in Imager::Draw β€” retrieves one or more pixel colors
  • getsamples() β€” getsamples() in Imager::Draw β€” retrieves samples from a row or partial row of pixels
  • getscanline() β€” getscanline() in Imager::Draw β€” retrieves colors for a row or partial row of pixels
  • getwidth() β€” getwidth() in Imager::ImageTypes β€” width of the image in pixels
  • img_set() β€” img_set() in Imager::ImageTypes β€” re-uses an Imager object for a new image
  • init() β€” init() in Imager::ImageTypes
  • is_bilevel() β€” is_bilevel() in Imager::ImageTypes β€” returns whether image write functions should write the image in their bilevel (blank and white, no gray levels) format
  • is_logging() β€” is_logging() in Imager::ImageTypes β€” tests if the debug log is active
  • line() β€” line() in Imager::Draw β€” draws an interval
  • load_plugin() β€” load_plugin() in Imager::Filters
  • log() β€” log() in Imager::ImageTypes β€” sends a message to the debugging log
  • make_palette() β€” make_palette() in Imager::ImageTypes β€” produces a color palette from one or more input images
  • map() β€” map() in Imager::Transformations β€” remaps color channel values
  • masked() β€” masked() in Imager::ImageTypes β€” makes a masked image
  • matrix_transform() β€” matrix_transform() in Imager::Engines
  • maxcolors() β€” maxcolors() in Imager::ImageTypes
  • NC() β€” NC() in Imager::Handy
  • NCF() β€” NCF() in Imager::Handy
  • new() β€” new() in Imager::ImageTypes
  • newcolor() β€” newcolor() in Imager::Handy
  • newcolour() β€” newcolour() in Imager::Handy
  • newfont() β€” newfont() in Imager::Handy
  • NF() β€” NF() in Imager::Handy
  • open() β€” read() in Imager::Files β€” an alias for read()
  • open_log() β€” open_log() in Imager::ImageTypes β€” opens the debug log
  • parseiptc() β€” parseiptc() in Imager::Files β€” parses IPTC data from a JPEG image
  • paste() β€” paste() in Imager::Transformations β€” draws an image onto an image
  • polygon() β€” polygon() in Imager::Draw
  • polyline() β€” polyline() in Imager::Draw
  • polypolygon() β€” polypolygon() in Imager::Draw
  • preload() β€” preload() in Imager::Files
  • read() β€” read() in Imager::Files β€” reads a single image from an image file
  • read_multi() β€” read_multi() in Imager::Files β€” reads multiple images from an image file
  • read_types() β€” read_types() in Imager::Files β€” lists image types Imager can read
  • register_filter() β€” register_filter() in Imager::Filters
  • register_reader() β€” register_reader() in Imager::Files
  • register_writer() β€” register_writer() in Imager::Files
  • rgb_difference() β€” rgb_difference() in Imager::Filters β€” produces a difference images from two input images
  • rotate() β€” rotate() in Imager::Transformations
  • rubthrough() β€” rubthrough() in Imager::Transformations β€” draws an image onto an image and uses the alpha channel
  • scale() β€” scale() in Imager::Transformations
  • scale_calculate() β€” scale_calculate() in Imager::Transformations
  • scaleX() β€” scaleX() in Imager::Transformations
  • scaleY() β€” scaleY() in Imager::Transformations
  • setcolors() β€” setcolors() in Imager::ImageTypes β€” sets palette colors in a paletted image
  • set_file_limits() β€” set_file_limits() in Imager::Files
  • setmask() β€” setmask() in Imager::ImageTypes
  • setpixel() β€” setpixel() in Imager::Draw
  • setsamples() β€” setsamples() in Imager::Draw
  • setscanline() β€” setscanline() in Imager::Draw
  • settag() β€” settag() in Imager::ImageTypes
  • string() β€” string() in Imager::Draw β€” draws text on an image
  • tags() β€” tags() in Imager::ImageTypes β€” fetches image tags
  • to_paletted() β€” to_paletted() in Imager::ImageTypes
  • to_rgb16() β€” to_rgb16() in Imager::ImageTypes
  • to_rgb8() β€” to_rgb8() in Imager::ImageTypes
  • to_rgb_double() β€” to_rgb_double() in Imager::ImageTypes β€” converts to double per sample image
  • transform() β€” transform() in Imager::Engines
  • transform2() β€” transform2() in Imager::Engines
  • trim() β€” trim() in Imager::Transformations β€” returns a cropped image based on border transparency or border colors
  • trim_rect() β€” trim_rect() in Imager::Transformations β€” returns how much trim() would remove
  • type() β€” type() in Imager::ImageTypes β€” type of image (direct vs paletted)
  • unload_plugin() β€” unload_plugin() in Imager::Filters
  • virtual() β€” virtual() in Imager::ImageTypes β€” whether the image has it's own data
  • write() β€” write() in Imager::Files β€” writes an image to a file
  • write_multi() β€” write_multi() in Imager::Files β€” writes multiple image to an image file
  • write_types() β€” read_types() in Imager::Files β€” lists image types Imager can write

pro tip bestie: a bunch of these cross-reference lines point at a different method name than the one you searched β€” like colormodel() sending you to colorcount(), or write_types() sending you to read_types(). that's not a typo on my end, that's literally what the docs say, so follow the breadcrumbs fr fr 🫢

πŸ”Ž CONCEPT INDEX πŸ”Ž

okay so this is basically the group chat's "who's who" of Imager β€” you look up a thing you wanna do and it tells you which page has the tea. find your vibe, click through, slay πŸ’…

  • animated GIF β€” "Writing an animated GIF" in Imager::Files
  • aspect ratio β€” "i_xres", "i_yres", "i_aspect_only" in "Common Tags" in Imager::ImageTypes.
  • blend β€” alpha blending one image onto another "rubthrough()" in Imager::Transformations
  • blur β€” ""gaussian"" in Imager::Filters, ""conv"" in Imager::Filters
  • boxes, drawing β€” "box()" in Imager::Draw
  • changes between image β€” "Image Difference" in Imager::Filters
  • channels, combine into one image β€” "combine()" in Imager::Transformations
  • color β€” Imager::Color
  • color names β€” Imager::Color, Imager::Color::Table
  • combine modes β€” "Combine Types" in Imager::Draw
  • compare images β€” "Image Difference" in Imager::Filters
  • contrast β€” ""contrast"" in Imager::Filters, ""autolevels"" in Imager::Filters
  • convolution β€” ""conv"" in Imager::Filters
  • cropping β€” "crop()" in Imager::Transformations, "trim()" in Imager::Transformations
  • CUR files β€” "ICO (Microsoft Windows Icon) and CUR (Microsoft Windows Cursor)" in Imager::Files
  • "diff" images β€” "Image Difference" in Imager::Filters
  • dpi β€” "i_xres", "i_yres" in "Common Tags" in Imager::ImageTypes, "Image spatial resolution" in Imager::Cookbook
  • drawing boxes β€” "box()" in Imager::Draw
  • drawing lines β€” "line()" in Imager::Draw
  • drawing text β€” "string()" in Imager::Draw, "align_string()" in Imager::Draw
  • error message β€” "ERROR HANDLING"
  • files, font β€” Imager::Font
  • files, image β€” Imager::Files
  • filling, types of fill β€” Imager::Fill
  • filling, boxes β€” "box()" in Imager::Draw
  • filling, flood fill β€” "flood_fill()" in Imager::Draw
  • flood fill β€” "flood_fill()" in Imager::Draw
  • fonts β€” Imager::Font
  • fonts, drawing with β€” "string()" in Imager::Draw, "align_string()" in Imager::Draw, Imager::Font::Wrap
  • fonts, metrics β€” "bounding_box()" in Imager::Font, Imager::Font::BBox
  • fonts, multiple master β€” "MULTIPLE MASTER FONTS" in Imager::Font
  • fountain fill β€” "Fountain fills" in Imager::Fill, ""fountain"" in Imager::Filters, Imager::Fountain, ""gradgen"" in Imager::Filters
  • GIF files β€” "GIF" in Imager::Files
  • GIF files, animated β€” "Writing an animated GIF" in Imager::Files
  • gradient fill β€” "Fountain fills" in Imager::Fill, ""fountain"" in Imager::Filters, Imager::Fountain, ""gradgen"" in Imager::Filters
  • gray scale, convert image to β€” "convert()" in Imager::Transformations
  • gaussian blur β€” ""gaussian"" in Imager::Filters, ""gaussian2"" in Imager::Filters
  • hatch fills β€” "Hatched fills" in Imager::Fill
  • ICO files β€” "ICO (Microsoft Windows Icon) and CUR (Microsoft Windows Cursor)" in Imager::Files
  • invert image β€” ""hardinvert"" in Imager::Filters, ""hardinvertall"" in Imager::Filters
  • JPEG β€” "JPEG" in Imager::Files
  • limiting image sizes β€” "Limiting the sizes of images you read" in Imager::Files
  • lines, drawing β€” "line()" in Imager::Draw
  • matrix β€” Imager::Matrix2d, "Matrix Transformations" in Imager::Engines, "transform()" in Imager::Font
  • metadata, image β€” "Tags" in Imager::ImageTypes, Image::ExifTool
  • mosaic β€” ""mosaic"" in Imager::Filters
  • noise, filter β€” ""noise"" in Imager::Filters
  • noise, rendered β€” ""turbnoise"" in Imager::Filters, ""radnoise"" in Imager::Filters
  • paste β€” "paste()" in Imager::Transformations, "rubthrough()" in Imager::Transformations
  • pseudo-color image β€” "to_paletted()" in Imager::ImageTypes, "new()" in Imager::ImageTypes
  • posterize β€” ""postlevels"" in Imager::Filters
  • PNG files β€” Imager::Files, "PNG" in Imager::Files
  • PNM β€” "PNM (Portable aNy Map)" in Imager::Files
  • rectangles, drawing β€” "box()" in Imager::Draw
  • resizing an image β€” "scale()" in Imager::Transformations, "crop()" in Imager::Transformations
  • RGB (SGI) files β€” "SGI (RGB, BW)" in Imager::Files
  • saving an image β€” Imager::Files
  • scaling β€” "scale()" in Imager::Transformations
  • security β€” Imager::Security
  • SGI files β€” "SGI (RGB, BW)" in Imager::Files
  • sharpen β€” ""unsharpmask"" in Imager::Filters, ""conv"" in Imager::Filters
  • size, image β€” "getwidth()" in Imager::ImageTypes, "getheight()" in Imager::ImageTypes
  • size, text β€” "bounding_box()" in Imager::Font
  • tags, image metadata β€” "Tags" in Imager::ImageTypes
  • text, drawing β€” "string()" in Imager::Draw, "align_string()" in Imager::Draw, Imager::Font::Wrap
  • text, wrapping text in an area β€” Imager::Font::Wrap
  • text, measuring β€” "bounding_box()" in Imager::Font, Imager::Font::BBox
  • threads β€” Imager::Threads
  • tiles, color β€” ""mosaic"" in Imager::Filters
  • transparent images β€” Imager::ImageTypes, "Transparent PNG" in Imager::Cookbook
  • unsharp mask β€” ""unsharpmask"" in Imager::Filters
  • watermark β€” ""watermark"" in Imager::Filters
  • writing an image to a file β€” Imager::Files

🫢 SUPPORT 🫢

bestie, if you're stuck, the mailing list is genuinely the best place to get help with Imager. that's the main character of support channels, no cap.

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 πŸ‘€ (yes, the receipts are public).

you can report bugs either via github at:

https://github.com/tonycoz/imager/issues

or 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 πŸ’– (like, the bug report is only as iconic as the info you give it)

🌈 CONTRIBUTING TO IMAGER 🌈

πŸ’¬ Feedback

I like feedback.

you can 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. lowkey the tests are the vibe check, ngl.

to browse Imager's git repository:

https://github.com/tonycoz/imager.git

to clone:

git clone git://github.com/tonycoz/imager.git

or you can create a fork as usual on github and submit a github pull request πŸŽ€

patches can either be submitted as a github pull request or by using 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. (the whole squad fr fr 🫢)


πŸ’œ 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. (legal girlies stay winning ✨)


⭐ 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 http://www.graphicsmagick.org/perl.html(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.


and that's the whole page, bestie!! this lil' beauty came from perl v5.42.3, dated 2026-08-19, and it's Imager(3pm) πŸ’…βœ¨ go forth and make iconic images πŸ¦‹πŸ’–πŸŽ€

πŸ“¦ where this page comes from