perl 生成SVG 的xml 文件

use SVG;

# new SVG

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

# text object , 关键是字体类型,起先只用 ‘font’ => 'Arial',网页显示的字体看起来不是Arial,不知道为啥呢。总之设置成‘font-family’,就好了。

$svg -> text(
id =>'txttitle',
x => 100,
y => 50,
style => {'font-family'=>'Arial, Helvetica, sans-serif', 'font-size'=>40}
)->cdata($txt_header);

 

# line object

$svg->line(
id=>"line".$m,
x1=>$border, y1=>$abs_high+($tmprow+1)*($border+$image_high)+30,
x2=>$ncol*($border+$image_width), y2=>$abs_high+($tmprow+1)*($border+$image_high)+30,
style=>{'stroke-width'=>'2.5','stroke'=>'black'}
);

 

# image object

$svg->image(
x=>($tmpcol+1)*$border+$tmpcol*$image_width+40, y=>$abs_high+($tmprow+1)*$border+$tmprow*$image_high,
width=>$image_width, height=>$image_high,
'-href'=>"$txt_header/$plt_name[$m].jpg", #may also embed SVG, e.g. "image.svg"
id=> "image$m"
);

 

# output svg object as xml format

open(OUT,">$txt_header.svg") || die;

print OUT $svg->xmlify;
close OUT;

# 以上都是在SVG 显示中常见的object,如果需要其他的,查看 http://search.cpan.org/~ronan/SVG-2.28/SVG/Manual.pm

#每个object 大小和位置可根据需要,自行调整。 

 

posted on 2016-07-07 14:10  sophie_sisi  阅读(520)  评论(0编辑  收藏  举报

导航