-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathREADME
168 lines (120 loc) · 5.43 KB
/
README
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
NAME
Image::WordCloud - Create word cloud images
SYNOPSIS
use Image::WordCloud;
use File::Slurp;
my $wc = Image::WordCloud->new();
# Add the Gettysburg Address
my $text = read_file('script/gettysburg.txt');
$wc->words($text);
# Create the word cloud as a GD image
my $gd = $wc->cloud();
open(my $fh, '>', 'gettysburg.png');
binmode $fh;
print $fh $gd->png();
close($fh);
# See examples/gettysburg.png for how the created image looks.
# script/gettysburg.pl will create it
# The calls can also be chained like so:
my $text = read_file('script/gettysburg.txt');
my $gd = Image::WordCloud->new()
->words($text)
->cloud();
Create "word cloud" images from a set of specified words, similar to
http://wordle.net. Font size indicates the frequency with which a word
is used.
Colors are generated randomly using Color::Scheme. Fonts can be
specified or chosen randomly.
FUNCTIONS
new( ... )
Accepts a number of parameters to alter the image look.
* image_size => [$x, $y]
Sets the size of the image in pixels, accepts an arrayref. Defaults
to [400, 400].
NOTE: Non-square images currently can look a little squirrely due to
how Math::TheodorusSpiral fills a rectangle.
* word_count => $count
Number of words to show on the image. Defaults to 70.
* prune_boring => <1,0>
Prune "boring", or "stop" words. This module currently only supports
English stop words (like 'the', 'a', 'and', 'but'). The full list is
in Image::WordCloud::StopWords::EN
Defaults to true.
* font => $name
Name of font to use. This is passed directly to GD::Text::Align so
it can either be a string like 'arial', or a full path. However in
order for non-path font names to work, GD needs an environment
variable like FONT_PATH or FONT_TT_PATH to be set, or `font_path'
can be used to set it manually.
* font_path => $path_to_fonts
Set where your font .ttf files are located. If this is not
specified, the path of this module's distribution directory will be
used via File::ShareDir. Currently this module comes bundled with
one set of fonts.
* background => [$r, $g, $b]
Takes an arrayref defining the background color to use. Defaults to
[40, 40, 40]
* border_padding => <$pixels | $percent>
Padding to leave clear around the edges of the image, either in
pixels or a percent with '%' sign. Defaults to '5%'
my $wc = Image::WordCloud->new(border_padding => 20);
my $wc = Image::WordCloud->new(border_padding => '25%');
Please note that this affects the speed with which this module can
fit words into the image. In my tests on the text of the Declaration
of Independence, bumping the percentage by 5% increments progressed
like so:
0%: 15.25s
5%: 21.50s
10%: 30.00s
15%: 63.6s avg
words(\%words_to_use | \@words | @words_to_use | $words)
Takes either a hashref, arrayref, array or string.
If the argument is a hashref, keys are the words, values are their
count. No further processing is done (we assume you've done it on your
own).
If the argument is an array, arrayref, or string, the words are parsed
to remove non-word characters and turn them lower-case.
cloud()
Make the word cloud. Returns a GD::Image.
my $gd = Image::WordCloud->new()->words(qw/some words etc/)->cloud();
# Spit out the wordlcoud as a PNG
$gd->png;
# ... or a jpeg
$gd->jpg;
# Get the dimensions
$gd->width;
$gd->height;
# Or anything else you can do with a GD::Image object
add_stop_words(@words)
Add new stop words onto the list. Automatically puts words in lowercase.
width()
Return wordcloud image width
height()
Return wordcloud image height
AUTHOR
Brian Hann, `<bhann at cpan.org>'
BUGS
Please report any bugs or feature requests here
https://github.com/c0bra/image-wordcloud-perl/issues. I will be
notified, and then you'll automatically be notified of progress on your
bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Image::WordCloud
You can also look for information at:
* Github Issues Tracker (report bugs here)
https://github.com/c0bra/image-wordcloud-perl/issues
* AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Image-WordCloud
* CPAN Ratings
http://cpanratings.perl.org/d/Image-WordCloud
* Search CPAN
http://search.cpan.org/dist/Image-WordCloud/
* MetaCPAN
https://metacpan.org/module/Image::WordCloud
LICENSE AND COPYRIGHT
Copyright 2012 Brian Hann.
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.