SVG
view release on metacpan or search on metacpan
fill => 'green'
},
);
# add a circle to the group
$y->circle( cx => 100, cy => 100, r => 50, id => 'circle_in_group_y' );
# or, use the generic 'tag' method to generate a group element by name
my $z = $svg->tag('g',
id => 'group_z',
style => {
stroke => 'rgb(100,200,50)',
fill => 'rgb(10,100,150)'
}
);
# create and add a circle using the generic 'tag' method
$z->tag('circle', cx => 50, cy => 50, r => 100, id => 'circle_in_group_z');
# create an anchor on a rectangle within a group within the group z
my $k = $z->anchor(
id => 'anchor_k',
-href => 'http://test.hackmare.com/',
target => 'new_window_0'
)->rectangle(
x => 20, y => 50,
width => 20, height => 30,
rx => 10, ry => 5,
id => 'rect_k_in_anchor_k_in_group_z'
);
# now render the SVG object, implicitly use svg namespace
print $svg->xmlify;
# or render a child node of the SVG object without rendering the entire object
print $k->xmlify; #renders the anchor $k above containing a rectangle, but does not
#render any of the ancestor nodes of $k
# or, explicitly use svg namespace and generate a document with its own DTD
print $svg->xmlify(-namespace=>'svg');
# or, explicitly use svg namespace and generate an inline docunent
print $svg->xmlify(
-namespace => "svg",
-pubid => "-//W3C//DTD SVG 1.0//EN",
-inline => 1
);
See the other modules in this distribution:
L<SVG::DOM>,
L<SVG::XML>,
L<SVG::Element>,
and L<SVG::Extension>.
See L<SVG::Parser> for reading SVG files as C<SVG> objects.
=head2 Converting SVG to PNG and other raster image formats
The B<convert> command of L<http://www.imagemagick.org/> (also via L<Image::Magick> ) can convert SVG files to PNG
and other formats.
L<Image::LibRSVG> can convert SVG to other format.
=head1 EXAMPLES
examples/circle.pl generates the following image:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg height="200" width="200" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title >I am a title</title>
<g id="group_y" style="fill: green; stroke: red">
<circle cx="100" cy="100" id="circle_in_group_y" r="50" />
<!-- This is a comment -->
</g>
</svg>
That you can either embed directly into HTML or can include it using:
<object data="file.svg" type="image/svg+xml"></object>
=for HTML <p><img src="http://szabgab.com/img/SVG/circle.png" alt="SVG example circle" /></p>
(The image was converted to png using L<Image::LibRSVG>. See the svg2png.pl script in the examples directory.)
=for HTML <p><img src="http://perlmaven.com/img/svg/circle.svg" alt="SVG example circle" /></p>
See also the B<examples> directory in this distribution which contains several fully documented examples.
=head1 DESCRIPTION
SVG is a 100% Perl module which generates a nested data structure containing the
DOM representation of an SVG (Scalable Vector Graphics) image. Using SVG, you
can generate SVG objects, embed other SVG instances into it, access the DOM
object, create and access javascript, and generate SMIL animation content.
=head2 General Steps to generating an SVG document
Generating SVG is a simple three step process:
=over 4
=item 1 Construct a new SVG object with L<"new">.
=item 2 Call element constructors such as L<"circle"> and L<"path"> to create SVG elements.
=item 3 Render the SVG object into XML using the L<"xmlify"> method.
=back
The L</xmlify> method takes a number of optional arguments that control how SVG
renders the object into XML, and in particular determine whether a standalone
SVG document or an inline SVG document fragment is generated:
=head2 -standalone
A complete SVG document with its own associated DTD. A namespace for the SVG
elements may be optionally specified.
( run in 2.135 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )