Image::SVG::Transform - read the "transform" attribute of an SVG element


version 0.08


    use Image::SVG::Transform;
    my $transform = Image::SVG::Transform->new();
    my $view_point = $transform->transform([5, 10]);


This module parses and converts the contents of the transform attribute in SVG into a series of array of hashes, and then provide a convenience method for doing point transformation from the transformed space to the viewpoint space.

This is useful if you're doing SVG rendering, or if you are trying to estimate the length of shapes in an SVG file.


The following methods are available.

new ()

Constructor for the class. It takes no arguments.


The list of transforms that were extracted from the transform string that submitted to extract_transforms. Each transform will be a hashref with these keys:


The type of transformation (scale, translate, skewX, matrix, skewY, rotate).


An arrayref of hashrefs. Each hashref has key for type (string) and params (arrayref of numeric parameters).


Returns true if the object has any transforms.


Clear the set of transforms


The combined transformation matrix for the set of transforms. This is a Math::Matrix object.

extract_transforms ( $svg_transformation )

Parses the $svg_transformation string, which is expected to contain a valid set of SVG transformations as described in section 7.6 of the SVG spec: Unrecognized transformation types, or valid types with the wrong number of arguments, will cause Image::SVG::Transform to croak with an error message.

After it is done parsing, it updates the stored transforms and clears the stored combined transformation matrix.

Passing in the empty string will clear the set of transformations.

In the following conditions, Image::SVG::Transform will throw an exception using Ouch:

The transform string could not be parsed
The transform contains un unknown type
The type of transform has the wrong number of arguments

transform ( $point )

Using the stored set of one or more transforms, transform $point from the local coordinate system to viewport coordinate system. The combined transformation matrix is cached so that it isn't recalculated everytime this method is called.

untransform ( $point )

The opposite of transform. It takes a point from the viewport coordinates and transforms them into the local coordinate system.


namespace::clean Math::Trig Math::Matrix Ouch Moo



Bug Reports


Colin Kuskie <colink_at_plainblack_dot_com>


Image::SVG::Path SVG::Estimate


Thank you to Ben Bullock, author of Image::SVG::Path for the regular expressions for the parser.


This module is Copyright 2016 Plain Black Corporation. It is distributed under the same terms as Perl itself.