<%args>
$imgtype => 'png'
$objectName
</%args>

<%init>
my $model = $m->notes('MODEL');
use File::Slurp;
use File::Temp qw/tempfile/;
my %typemap = (
    epsc => 'application/postscript',
    eps => 'application/postscript',
    png => 'image/png',
);

die "bogus image type: $imgtype" unless exists($typemap{$imgtype});
$r->content_type($typemap{$imgtype});

my $stuff = join '', `magtplot --instance $model --terminal $imgtype $objectName | gnuplot`;
$m->clear_buffer;
$m->print($stuff);
$m->abort;
</%init>
