Image::Base::SVG -- SVG image file output
use Image::Base::SVG; my $image = Image::Base::SVG->new (-width => 100, -height => 100); $image->rectangle (0,0, 99,99, 'black'); $image->xy (20,20, 'green'); $image->line (50,50, 70,70, 'red'); $image->line (50,50, 70,70, 'blue'); $image->save ('/some/filename.svg');
Image::Base::SVG is a subclass of Image::Base,
Image::Base::SVG
Image::Base
Image::Base Image::Base::SVG
Image::Base::SVG extends Image::Base to create or update SVG format image files using the SVG module. The SVG module holds the contents of an SVG file in memory as an object which can be variously manipulated. See SVG::Manual for details.
SVG
Image::Base is pixel oriented so isn't really the sort of thing SVG is meant for, but this module can direct Image::Base style code at an SVG object. The SVG module has many more features if used natively.
It's often fairly easy to spit out SVG directly too, and for instance the Image::Base::SVGout module can do that. The advantage of the SVG object comes when combining images or fragments, or going through elements for post-facto mangling.
Image::Base::SVGout
In the current code the SVG elements emitted assume some default style attributes such as stroke-width 1. Perhaps that should be set explicitly on each element.
Colour names are per the SVG spec, which is CSS style syntax
#RGB hex, 1 digit #RRGGBB hex, 2 digit rgb(255,255,255) integers 0 to 255 rgb(100%,100%,100%) percentages http://www.w3.org/TR/2008/REC-CSS2-20080411/syndata.html#value-def-color
plus extra names
http://www.w3.org/TR/2003/REC-SVG11-20030114/types.html#ColorKeywords
See "FUNCTIONS" in Image::Base for the behaviour common to all Image-Base classes.
$image = Image::Base::SVG->new (key=>value,...)
Create and return a new image object. A new image can be started with just
$image = Image::Base::SVG->new;
Generally -width and -height should be set, but it works to do that later after creating.
-width
-height
Or an existing SVG object can be given,
my $svg = SVG->new; ... $image = Image::Base::SVG->new (-svg_object => $svg);
$image->xy ($x, $y, $colour)
$colour = $image->xy ($x, $y)
Get or set an individual pixel.
Currently for a get the return is always undef as there's no support for picking out elements etc from the SVG. Perhaps the simple elements drawn by this Image::Base::SVG could be read back, but arbitrary SVG from a load() would need a full rasterize in the worst case.
undef
load()
$image->load ()
$image->load ($filename)
Load an SVG file into $image, either from the current -file attribute, or set that to $filename then load.
$image
-file
$filename
This uses the SVG::Parser module. See that module for how to choose between Expat or SAX for its underlying XML parse, and see in turn XML::SAX for its further choice of libxml, pure perl, etc. LibXML might be unhelpfully strict.
SVG::Parser
$image->save ()
$image->save ($filename)
Save the image to an SVG file, either the current -file option, or set that option to $filename and save to there.
Setting -width or -height changes the SVG canvas size. In the current code it doesn't affect the elements already drawn to it. Is that how it should be?
Image::Base, SVG, SVG::Manual, SVG::Parser
http://user42.tuxfamily.org/image-base-svg/index.html
Image-Base-SVG is Copyright 2011, 2012, 2019 Kevin Ryde
Image-Base-SVG is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Image-Base-SVG is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Image-Base-SVG. If not, see <http://www.gnu.org/licenses/>.
To install Image::Base::SVG, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Image::Base::SVG
CPAN shell
perl -MCPAN -e shell install Image::Base::SVG
For more information on module installation, please visit the detailed CPAN module installation guide.