Skip to content

Instantly share code, notes, and snippets.

@keedi
Created March 23, 2010 06:12
Show Gist options
  • Save keedi/340884 to your computer and use it in GitHub Desktop.
Save keedi/340884 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use 5.010;
use common::sense;
use List::Util qw( max );
use GD;
my $radius = 80;
my $font = '/home/keedi/.fonts/NanumGothic.ttf';
my $fontsize = 20;
my $color = '#0000FF';
my @strings = (
'a3r0',
'am0c',
'aqua',
'ascendo',
'darjeeling',
'envi',
'hanekomu',
'hshong',
'jaker',
'jeen',
'keedi',
'khj',
'LaVieEnRose',
'pjm0616',
'popeye92',
'pung96',
'sng2c',
'yongbin',
'yoong',
'yuni',
);
my $image = sabaltongmun(
$radius,
$font,
$fontsize,
$color,
@strings,
);
binmode STDOUT;
print $image->png;
sub sabaltongmun {
my ( $radius, $font, $fontsize, $color, @strings ) = @_;
my $max_string_width = max( map length, @strings ) * $fontsize;
my $cx = $radius + $max_string_width;
my $cy = $radius + $max_string_width;
my $width = ( $radius + $max_string_width ) * 2;
my $height = ( $radius + $max_string_width ) * 2;
my $angle = ( 2 * 3.14 ) / @strings;
#
# Make GD::Image
#
my $image = GD::Image->new($width, $height);
my $white = $image->colorAllocate( get_rgb("#FFFFFF") );
my $black = $image->colorAllocate( get_rgb("#000000") );
# make the background transparent and interlaced
$image->transparent( get_rgb("#FFFFFF") );
$image->interlaced('true');
my $dest_angle = 0;
for my $string ( @strings ) {
my $dest_x = $cx + ( $radius * cos $dest_angle );
my $dest_y = $cy + ( $radius * sin $dest_angle );
my $string_angle = (2 * 3.14) - $dest_angle;
$image->stringFT(
$image->colorAllocate( get_rgb($color) ), # fgcolor
$font, # .ttf path
$fontsize, # point size
$string_angle, # rotation angle
$dest_x, # X coordinates
$dest_y, # Y coordinates
$string,
{
linespacing => 0.6,
charmap => "Unicode",
},
);
$dest_angle += $angle;
}
return $image;
}
sub get_rgb { map hex, $_[0] =~ m/^#(..)(..)(..)$/ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment