Imager::Matrix2d(3pm)

๐Ÿ’– NAME ๐Ÿ’–

okay bestie, welcome to the Imager::Matrix2d(3pm) manual page โ€” it's literally a simple wrapper for matrix construction, and it's lowkey iconic. ๐Ÿ’…

โœจ SYNOPSIS โœจ

use Imager::Matrix2d;
$m1 = Imager::Matrix2d->identity;
$m2 = Imager::Matrix2d->rotate(radians=>$angle, x=>$cx, y=>$cy);
$m3 = Imager::Matrix2d->translate(x=>$dx, y=>$dy);
$m4 = Imager::Matrix2d->shear(x=>$sx, y=>$sy);
$m5 = Imager::Matrix2d->reflect(axis=>$axis);
$m6 = Imager::Matrix2d->scale(x=>$xratio, y=>$yratio);
$m8 = Imager::Matric2d->matrix($v11, $v12, $v13,
                               $v21, $v22, $v23,
                               $v31, $v32, $v33);
$m6 = $m1 * $m2;
$m7 = $m1 + $m2;
use Imager::Matrix2d qw(:handy);
# various m2d_* functions imported
# where m2d_(.*) calls Imager::Matrix2d->$1()

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

Okay so this class is a simple wrapper around a reference to an array of 9 coefficients, treated as a matrix:

[ 0, 1, 2,
  3, 4, 5,
  6, 7, 8 ]

Most of the methods in this class are constructors. The others are overloaded operators. Slay. โœจ

โš ๏ธ important vibe check: since Imager represents images with y increasing from top to bottom, rotation angles are clockwise, not counter-clockwise. That's just the rule, bestie. ๐Ÿ”„

identity() ๐Ÿ’–

Returns the identity matrix.

rotate(radians=>$angle) / rotate(degrees=>$angle) ๐ŸŒ€

Creates a matrix that rotates around the origin, or around the point (x,y) if the 'x' and 'y' parameters are provided.

translate(x=>$dx, y=>$dy), translate(x=>$dx), translate(y=>$dy) ๐Ÿ›ผ

Translates by the specify amounts.

shear(x=>$sx, y=>$sy), shear(x=>$sx), shear(y=>$sy) ๐Ÿช„

Shear by the given amounts.

reflect(axis=>$axis) ๐Ÿชž

Reflect around the given axis, either 'x' or 'y'.

reflect(radians=>$angle) / reflect(degrees=>$angle) ๐ŸŒˆ

Reflect around a line drawn at the given angle from the origin.

scale(x=>$xratio, y=>$yratio) ๐Ÿ“

Scales at the given ratios.

You can also specify a center for the scaling with the "cx" and "cy" parameters.

matrix($v11, $v12, $v13, $v21, $v22, $v23, $v31, $v32, $v33) ๐Ÿงฎ

Create a matrix with custom coefficients.

transform($x, $y) โœจ

Transform a point the same way matrix_transform does.

compose(matrix...) ๐ŸŽ€

Compose several matrices together for use in transformation.

For example, for three matrices:

my $out = Imager::Matrix2d->compose($m1, $m2, $m3);

is equivalent to:

my $out = $m3 * $m2 * $m1;

Returns the identity matrix if no parameters are supplied.

May return the supplied matrix if only one matrix is supplied.

_mult() ๐Ÿ”ฅ

Implements the overloaded '*' operator. Internal use.

Currently both the left and right-hand sides of the operator must be an Imager::Matrix2d.

When composing a matrix for transformation you should multiply the matrices in the reverse order of the transformations:

my $shear = Imager::Matrix2d->shear(x => 0.1);
my $rotate = Imager::Matrix2d->rotate(degrees => 45);
my $shear_then_rotate = $rotate * $shear;

or use the compose method:

my $shear_then_rotate = Imager::Matrix2d->compose($shear, $rotate);

_add() โž•

Implements the overloaded binary '+' operator.

Currently both the left and right sides of the operator must be Imager::Matrix2d objects.

_string() ๐Ÿงต

Implements the overloaded stringification operator.

This returns a string containing 3 lines of text with no terminating newline.

I tried to make it fairly nicely formatted. You might disagree :)

_eq โš–๏ธ

Implement the overloaded equality operator.

Provided for older perls that don't handle magic auto generation of eq from "".

๐ŸŒŸ the handy shortcut functions ๐ŸŒŸ

The following functions are shortcuts to the various constructors.

These are not methods.

You can import these methods with:

use Imager::Matrix2d ':handy';
  • m2d_identity
  • m2d_rotate()
  • m2d_translate()
  • m2d_shear()
  • m2d_reflect()
  • m2d_scale()

๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Tony Cook <tony@develop-help.com> โ€” an absolute icon for this one. ๐Ÿ’œ

๐Ÿ’€ BUGS ๐Ÿ’€

Needs a way to invert a matrix. lowkey tragic, ngl ๐Ÿ˜ญ

๐ŸŒˆ SEE ALSO ๐ŸŒˆ


okay that's the whole page, bestie ๐Ÿซถ this is Imager::Matrix2d(3pm) from perl v5.42.3, dated 2026-08-19 โ€” slay and goodbye โœจ๐Ÿ’–๐ŸŽ€

๐Ÿ“ฆ where this page comes from