Imager::Fill(3pm)
๐ธ NAME ๐ธ
Imager::Fill โ general fill types, aka the glow-up your drawing functions deserve ๐
(this is the Imager::Fill(3pm) page, straight outta the User Contributed Perl Documentation collection ๐ซถ)
โจ SYNOPSIS โจ
use Imager;
use Imager::Fill;
my $fill1 = Imager::Fill->new(solid=>$color, combine=>$combine);
my $fill2 = Imager::Fill->new(hatch=>'vline2', fg=>$color1, bg=>$color2,
dx=>$dx, dy=>$dy);
my $fill3 = Imager::Fill->new(fountain=>$type, ...);
my $fill4 = Imager::Fill->new(image=>$img, ...);
my $fill5 = Imager::Fill->new(type => "opacity", other => $fill,
opacity => ...);
๐ฆ DESCRIPTION ๐ฆ
Okay so bestie, here's the tea: this module creates fill objects for use by most of the filled-area drawing functions. That's it, that's the whole vibe. ๐ฅ
Every single fill is created with the new method. No cap.
๐ new
my $fill = Imager::Fill->new(...);
The parameters you pass depend on which type of fill you're creating โ like, obviously. Scroll down for the details, iykyk. ๐
The currently available fills are:
solidhatchfountainโ similar to gradients in paint software, iconic behavior honestlyimageโ fill with an image, possibly transformed ๐opacityโ a lower opacity version of some other fill
๐ Common options ๐
combine
The way in which the fill data is combined with the underlying image. See "Combine Types" in Imager::Draw.
In general, colors can be specified as Imager::Color or Imager::Color::Float objects. The fill object will typically store both types and convert from one to the other. If a fill takes 2 color objects, they should have the same type โ matching energy only, fr fr. ๐
โญ SOLID FILLS โญ
my $fill = Imager::Fill->new(solid=>$color, combine =>$combine)
Creates a solid fill. The only required parameter is solid, which should be the color to fill with. Simple, clean, main character energy. โจ
A translucent red fill:
my $red = Imager::Fill->new(solid => "FF000080", combine => "normal");
๐ธ HATCHED FILLS ๐ธ
my $fill = Imager::Fill->new(hatch=>$type, fg=>$fgcolor, bg=>$bgcolor,
dx=>$dx, $dy=>$dy);
Creates a hatched fill. You can specify the following keywords:
hatchโ The type of hatch to perform. This can either be the numeric index of the hatch (not recommended, lowkey don't), the symbolic name of the hatch, or an array of 8 integers which specify the pattern of the hatch.
Hatches are represented as cells 8x8 arrays of bits, which limits their complexity. Small cell, big personality ๐
Current hatch names are:
check1x1,check2x2,check4x4โ checkerboards at various sizesvline1,vline2,vline4โ 1, 2, or 4 vertical lines per cellhline1,hline2,hline4โ 1, 2, or 4 horizontal lines per cellslash1,slash2โ 1 or 2/lines per cell.slosh1,slosh2โ 1 or 2\lines per cellgrid1,grid2,grid4โ 1, 2, or 4 vertical and horizontal lines per celldots1,dots4,dots16โ 1, 4 or 16 dots per cellstipple,stipple2โ see the samples ๐weaveโ I hope this one is obvious.cross1,cross2โ 2 densities of crosshatchvlozenge,hlozengeโ something like lozenge tilesscalesdown,scalesup,scalesleft,scalesrightโ Vaguely like fish scales in each direction. ๐tile_Lโ L-shaped tiles
fg,bgโ Thefgcolor is rendered where bits are set in the hatch, and thebgwhere they are clear. If you use a transparentfgorbg, and setcombine, you can overlay the hatch onto an existing image. Iconic layering move. ๐ซถ
fg defaults to black, bg to white.
dx,dyโ An offset into the hatch cell. Both default to zero.
A blue and white 4-pixel check pattern:
my $fill = Imager::Fill->new(hatch => "check2x2", fg => "blue");
You can call Imager::Fill->hatches for a list of hatch names. ๐
๐ง FOUNTAIN FILLS ๐ง
my $fill = Imager::Fill->new(fountain=>$ftype,
xa=>$xa, ya=>$ya, xb=>$xb, yb=>$yb,
segments=>$segments, repeat=>$repeat, combine=>$combine,
super_sample=>$super_sample, ssample_param=>$ssample_param);
This fills the given region with a fountain fill. It's exactly the same fill as the fountain filter, but it's restricted to the shape you're drawing, and the fountain parameter supplies the fill type โ and it's required. No skipping, bestie. โ ๏ธ
A radial fill from white to transparent centered on (50, 50) with a 50 pixel radius:
use Imager::Fountain;
my $segs = Imager::Fountain->simple(colors => [ "FFFFFF", "FFFFFF00" ],
positions => [ 0, 1 ]);
my $fill = Imager::Fill->new(fountain => "radial", segments => $segs,
xa => 50, ya => 50, xb => 0, yb => 50,
combine => "normal");
๐ผ๏ธ IMAGE FILLS ๐ผ๏ธ
my $fill = Imager::Fill->new(image=>$src, xoff=>$xoff, yoff=>$yoff,
matrix=>$matrix, combine => $combine);
Fills the given image with a tiled version of the given image. The first non-zero value of xoff or yoff will provide an offset along the given axis between rows or columns of tiles respectively.
The matrix parameter performs a co-ordinate transformation from the co-ordinates in the target image to the fill image co-ordinates. Linear interpolation is used to determine the fill pixel. You can use the Imager::Matrix2d class to create transformation matrices. ๐ฆ
Heads up: the matrix parameter will significantly slow down the fill. ๐ญ Gorgeous results though.
# some image to act as a texture
my $txim = Imager->new(...);
# simple tiling
my $fill = Imager::Fill->new(image => $txim);
# tile with a vertical offset
my $fill = Imager::Fill->new(image => $txim, yoff => 10);
# tile with a horizontal offset
my $fill = Imager::Fill->new(image => $txim, xoff => 10);
# rotated
use Imager::Matrix2d;
my $fill = Imager::Fill->new(image => $txim,
matrix => Imager::Matrix2d->rotate(degrees => 20));
๐ OPACITY MODIFICATION FILL ๐
my $fill = Imager::Fill->new(type => "opacity",
other => $fill, opacity => 0.25);
This can be used to make a fill that is a more translucent or opaque version of an existing fill. It's intended for use where you receive a fill object as a parameter and need to change the opacity. So polite of it honestly. ๐
Parameters:
type => "opacity"โ Requiredotherโ the fill to produce a modified version of. This must be anImager::Fillobject. Required.opacityโ multiplier for the source fill opacity. Default:0.5.
The source fill's combine mode is used.
my $hatch = Imager::Fill->new(hatch => "check4x4", combine => "normal");
my $fill = Imager::Fill->new(type => "opacity", other => $hatch);
๐ OTHER METHODS ๐
Imager::Fill->hatches
A list of all defined hatch names. All the icons, one directory. โจ
Imager::Fill->combines
A list of all combine types.
๐ฎ FUTURE PLANS ๐ฎ
I'm planning on adding the following types of fills:
checkerboardโ combines 2 other fills in a checkerboardcombineโ combines 2 other fills using the levels of an imageregmachโ uses thetransform2()register machine to create fills
(manifesting these into existence tbh ๐ฏ๏ธ)
๐ซถ AUTHOR ๐ซถ
Tony Cook <tony@develop-help.com>
๐ SEE ALSO ๐
that's the whole page bestie โ none of the details got left on read ๐ This gem comes from perl v5.42.3 and was dated 2026-08-19, and it's the Imager::Fill(3pm) manual in all its glory. Slay, go forth and fill things. ๐๐โญ
๐ฆ where this page comes from
- ubuntu stonking: libimager-perl 1.035+dfsg-1 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms