[Pdx-pm] SVG Images with Perl (was Re: ... about CPAN.)

Bryce Harrington bryce at osdl.org
Tue Nov 29 16:46:22 PST 2005


On Tue, Nov 29, 2005 at 04:12:14PM -0800, Andrew Clapp wrote:
> I guess I would like to know if it's possible/ethical/feasable to make
> images with perl, without using an image creation library like libpng that
> must be built and installed by the sysadmin.  I don't know how it works with
> other languages (java), but they seem to make cool interactive, image driven
> apps.  I want to do that with CGI too.  Currently, I must make all my images
> on the fly (Imager, libpng, freetype, blah, blah) and build imagemaps to
> make them clickably functional.  I can't imagine trying to get some hosting
> service droid to get all that working correctly for me (IE, if I did not
> have access to my own server), but maybe they are doing ok with that these
> days.
> 
> Is there a better way?  What's the latest along these lines with perl?

The past few days I've been playing around with Firefox 1.5's new SVG
capabilities.  It won't solve your problem but it's __really cool__.

Here's a mockup for a Perl-based game I'm working on (only works in
Firefox 1.5): 

    http://bryceharrington.org/mint.xhtml

The entire layout is done in Inkscape.  I just took the SVG, stripped
off the header, and pasted it into a .xhtml file, loaded it in Mozilla,
and bam, it looks great.

Even though it's pretty extremely browser dependent at this point, I am
really loving how easy it is to do fairly sophisticated layouts.  I had
to tweak a few things with the font sizes (still not perfect), but
otherwise am impressed with how close it is to how it looked in
Inkscape.  Plus, SVG (unlike Flash) is an open standard with support
from lots of other libs and tools, so I expect to see it grow quickly
and get supported under more browsers.  SVG is already partly supported
by Konqueror, IE, and Opera, although there's discrepancies between them
currently; I figure within a year or so those will be worked out.

I love with this approach that I can completely forget about image
maps, png rendering, and so on.  Hyperlinks are as simple as just
putting in something like this:

   <a xlink:href="http://foobar.com">
      <rect blah blah />
   </a>

The links conform to whatever the outline is.  Check the corners of the
Attack button in my screen mockup - the clickability extends exactly to
the boundary of that shape and no further.

Also, you can embed javascript in SVG.  I've got a mouseover experiment
going with the button in the top right corner, as an example.  Some
limited animation is also possible, though I haven't played with that
yet.

Where this'll tie into Perl...  My plan is to hook this up to DBI,
CGI::Fast and Template::Toolkit to make the interface DB driven.  TT is
able to templatify any XML language, so why not SVG?  8-)

Bryce

P.S., Oh and for the record, this game is going to be done as an open
source project, so if anyone else wants to play around with this stuff
too, just drop me a line.


More information about the Pdx-pm-list mailing list