SVG using Perl

On the last Rehovot Perl Monger meeting Tamir Lousky talked about the SVG Perl module and how to use Perl to produce really nice Scalable Vector Graphics.

While we had some initial technical difficulties Tamir showed us a number of really nice pictures. He first explained to us the differences between raster and vector graphics and how they both work. Then he showed us some XML files - after all SVG defines the graphics in XML format - and some Perl code that can generate the XML files in a more Perlish way.

His slides are available on the web site of the Rehovot Perl Mongers under SVG using Perl by Tamir Lousky

I typed in the example he gave:


  use strict;
  use warnings;

  use SVG;

  my $svg = SVG->new(
    width  => 200,
    height => 200,
  );

  my $grp = $svg->group(
    id => 'group_y',
    style => {
      stroke => 'red',
      fill   => 'green',
    },
  );

  $grp->circle(
    cx => 100,
    cy => 100,
    r  => 50,
    id => 'circle01',
  );

  print $svg->xmlify;


Installing the SVG module on Ubuntu GNU/Linux 9.10 was quite easy. I just typed cpan SVG and it got installed.

Then I could run the above script and save the output in a file:


  perl red_green_circle.pl > red_green_circle.svg

The result is a simple red circle with green filling visible here.

I enjoyed the talk very much and learned a new toy I can play with.