The segfault is caused by the
fill function. Your image is 25 x 25 pixels; the coordinate system starts at 0 and ends at 24, so 25 is just one position too much. A fence-post error, if you will.
Here's the new version of your code, cleaned up slightly (I had nothing better to do. Sue me):
#!/usr/local/bin/perl -w
use strict;
use GD;
my %arcdata = (
topRight => [ 0, 24, 50, 50, 270, 360 ],
topLeft => [ 24, 24, 50, 50, 180, 270 ],
bottomRight => [ 0, 0, 50, 50, 0, 90 ],
bottomLeft => [ 24, 0, 50, 50, 90, 180 ]
);
for my $orientation ( keys %arcdata ) {
my @insertdata = @{ $arcdata{$orientation} };
my $img = new GD::Image (25, 25);
my $white = $img->colorAllocate(255,255,255);
$img->transparent($white);
my $black = $img->colorAllocate(0,0,0);
$img->arc(@insertdata, $black);
my $red = $img->colorAllocate(255,0,0);
$img->fill( @insertdata[0,1], $red);
open (IMAGEOUT,">$orientation.png") || die "Can't write to $or
+ientation.png: $!\n";
binmode (IMAGEOUT);
print IMAGEOUT $img->png();
close (IMAGEOUT);
print "wrote $orientation.png\n";
}
[ ar0n ]
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.