#!/usr/bin/env perl use 5.010; use strict; use warnings; # -------------------------------------- use GD; my @white = ( 0xFF, 0xFF, 0xFF ); my @black = ( 0x00, 0x00, 0x00 ); my $size = shift @ARGV || 400; my $offset = $size / 2; my $height = 0.9 * $offset; my $width = 0.1 * $offset; my $img = GD::Image->new( $size, $size, 1 ); $img->saveAlpha( 1 ); $img->alphaBlending( 1 ); # background color: black & transparent my $bg = $img->colorAllocateAlpha( @black, gdAlphaTransparent ); $img->fill( 0, 0, $bg ); # a simple polygon my $p = GD::Polygon->new(); $p->addPt( $offset + $width, $offset + 0 ); $p->addPt( $offset + 0, $offset - $height ); $p->addPt( $offset - $width, $offset + 0 ); $p->addPt( $offset + 0, $offset + $width ); # polygon color: black & opaque my $clr = $img->colorAllocateAlpha( @black, gdAlphaOpaque ); $img->setAntiAliased( $clr ); $img->filledPolygon( $p, gdAntiAliased ); # for testing, use script name for PNG file my $png_file = "$0.png"; open my $fh, '>:raw', $png_file or die "could not open $png_file: $!\n"; print {$fh} $img->png() or die "could not print to $png_file: $!\n"; close $fh or die "could not close $png_file: $!\n"; __END__ #### #!/usr/bin/env perl use 5.010; use strict; use warnings; # -------------------------------------- use GD; my @white = ( 0xFF, 0xFF, 0xFF ); my @black = ( 0x00, 0x00, 0x00 ); my $size = shift @ARGV || 400; my $offset = $size / 2; my $height = 0.9 * $offset; my $width = 0.1 * $offset; my $img = GD::Image->new( $size, $size, 1 ); $img->saveAlpha( 1 ); $img->alphaBlending( 1 ); # background color: white & transparent my $bg = $img->colorAllocateAlpha( @white, gdAlphaTransparent ); $img->fill( 0, 0, $bg ); # a simple polygon my $p = GD::Polygon->new(); $p->addPt( $offset + $width, $offset + 0 ); $p->addPt( $offset + 0, $offset - $height ); $p->addPt( $offset - $width, $offset + 0 ); $p->addPt( $offset + 0, $offset + $width ); # polygon color: black & opaque my $clr = $img->colorAllocateAlpha( @black, gdAlphaOpaque ); $img->setAntiAliased( $clr ); $img->filledPolygon( $p, gdAntiAliased ); # for testing, use script name for PNG file my $png_file = "$0.png"; open my $fh, '>:raw', $png_file or die "could not open $png_file: $!\n"; print {$fh} $img->png() or die "could not print to $png_file: $!\n"; close $fh or die "could not close $png_file: $!\n"; __END__