File: image_sample.pl

package info (click to toggle)
libsvg-perl 2.87-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 464 kB
  • sloc: perl: 2,789; makefile: 2
file content (55 lines) | stat: -rwxr-xr-x 1,824 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/perl

use strict;
use warnings;

#
# Incorporating an SVG image into another SVG image as an image object.
#
#

use SVG;
use CGI ':new :header';
my $p = CGI->new;
$| = 1;

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

$svg->desc( id=>'root-desc')->cdata('hello this is a description');

$svg->title( id=>'root-title')->cdata('Dynamic SVG - Image usage within SVG using Perl');

#use another SVG component as an image inside our image

$svg->image(id=>'image_1',
                      -href=>'SVG_02_sample.pl',
                      x=>150,
                      y=>150,
                      width=>100,
                      height=>100);  



#create a link to an other site through a png image
#We must first generate an anchor tag, give it agroup as a child, 
#and put the image as a child in it.

$svg->anchor('-href'=>"http://www.hackmare.com/",target=>'new_window')
    ->group(id=>'png_group')
    ->image(id=>'image_2',
            -href=>'http://www.hackmare.com/icons/logo/hackmaresplash600_1.png',
            x=>10,
            y=>10,
            width=>600,
            height=>94,);  

$svg->text(x=>20,y=>280)->cdata('EXPLANATION');  
$svg->text(x=>20,y=>310)->cdata('One image is imported as a full SVG image');  
$svg->text(x=>20,y=>325)->cdata('The second (hackmare) image is imported is an .png image');  
$svg->text(x=>20,y=>340)->cdata('Notice that the hackmare image contains a url anchor');  
$svg->text(x=>20,y=>355,style=>{fill=>'red'})->cdata('Actually, the link anchor contains a group which contains the image');  
$svg->text(x=>200,y=>385,style=>{fill=>'red','fill-opacity'=>0.2})->cdata("This image was generated with perl using Ronan Oger's SVG module");  
print $p->header('image/svg-xml');

print $svg->xmlify;
print "\n";