]> git.imager.perl.org - imager.git/blame - samples/hatches.pl
(rt #127575) link to Imager::Install from Imager::Files
[imager.git] / samples / hatches.pl
CommitLineData
f1ac5027
TC
1#!perl -w
2use strict;
3use Imager ':handy'; # handy functions like NC
4use Imager::Fill;
5use HTML::Entities;
6
7if (!-d 'hatches') {
8 mkdir 'hatches'
9 or die "hatches directory does not exist and could not be created: $!";
10}
11
12open HTML, "> hatches.html"
13 or die "Cannot create hatches.html: $!";
14print HTML <<EOS;
15<HTML><HEAD><TITLE>Imager - Hatched Fills</TITLE></HEAD><BODY BGCOLOR="FFFFFF">
16
17<CENTER><FONT FACE="Helvetica, Arial" SIZE="6" COLOR="CC0000"><B>
18Hatched Fills
19</FONT></B></CENTER>
20<HR WIDTH="65%" NOSHADE>
21<TABLE><TR><TD WIDTH="70%">
22
23<TABLE>
24<TR><TH>Filled area</TH><TH>Close-up</TH><TH>Name</TH></TR>
25EOS
26
27my $red = NC(255, 0, 0);
28my $yellow = NC(255, 255, 0);
29
30# sort of a spiral
31my $custom = [ 0xFF, 0x01, 0x7D, 0x45, 0x5D, 0x41, 0x7F, 0x00 ];
32
33for my $hatch (Imager::Fill->hatches, $custom) {
34 my $area = Imager->new(xsize=>100, ysize=>100);
35 $area->box(xmax=>50, fill => { hatch => $hatch });
36 $area->box(xmin=>50,
37 fill => { hatch => $hatch,
38 fg=>$red,
39 bg=>$yellow });
40 my $name = ref($hatch) ? "custom" : $hatch;
41
42 $area->write(file=>"hatches/area_$name.png")
43 or die "Cannot save hatches/area_$name.png: ",$area->errstr;
44
45 my $subset = $area->crop(width=>20, height=>20);
46 # we use the HTML to zoom up
47 $subset->write(file=>"hatches/zoom_$name.png")
48 or die "Cannot save hatches/zoom_$name.png: ",$subset->errstr;
49
50 print HTML <<EOS;
51<TR>
52 <TD><IMG SRC="hatches/area_$name.png" WIDTH="100" HEIGHT="100" BORDER=1></TD>
53 <TD><IMG SRC="hatches/zoom_$name.png" WIDTH="100" HEIGHT="100" BORDER=1></TD>
54 <TD>$name</TD>
55</TR>
56EOS
57}
58
59print HTML <<EOS;
60</TABLE>
61
62<P>The following code was used to generate this page:</p>
63
64<PRE>
65EOS
66
67open SELF, "< $0"
68 or die "Can't open myself: $!";
69while (<SELF>) {
70 print HTML encode_entities($_);
71}
72close SELF;
73
74print HTML <<EOS;
75</PRE>
76
77<HR WIDTH="75%" NOSHADE ALIGN="LEFT">
78
79Send errors/fixes/suggestions to: <B>tony</B>_at_<B>develop-help.com</B>
80
81</TD></TR></TABLE>
82</BODY>
83</HTML>
84EOS
85
86close HTML;