Class: Txt2img::Txt
Instance Attribute Summary collapse
-
#font ⇒ Object
Returns the value of attribute font.
-
#pointsize ⇒ Object
Returns the value of attribute pointsize.
-
#txt ⇒ Object
Returns the value of attribute txt.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #height ⇒ Object
-
#initialize(txt, options = {}) ⇒ Txt
constructor
A new instance of Txt.
-
#wrap! ⇒ Object
TODO optimize TODO NOT break English word TODO tune the margin and text size.
- #write(path) ⇒ Object
Methods included from StringUtil
#size, #split_by_width, #wrap_by_width
Constructor Details
#initialize(txt, options = {}) ⇒ Txt
Returns a new instance of Txt.
13 14 15 16 17 18 |
# File 'lib/txt2img.rb', line 13 def initialize(txt, = {}) @txt = txt @font = [:font] || File.("../../fonts/microhei.ttc", __FILE__) @width = [:width] || 20 @pointsize = [:pointsize] || 30 end |
Instance Attribute Details
#font ⇒ Object
Returns the value of attribute font.
11 12 13 |
# File 'lib/txt2img.rb', line 11 def font @font end |
#pointsize ⇒ Object
Returns the value of attribute pointsize.
11 12 13 |
# File 'lib/txt2img.rb', line 11 def pointsize @pointsize end |
#txt ⇒ Object
Returns the value of attribute txt.
11 12 13 |
# File 'lib/txt2img.rb', line 11 def txt @txt end |
#width ⇒ Object
Returns the value of attribute width.
11 12 13 |
# File 'lib/txt2img.rb', line 11 def width @width end |
Instance Method Details
#height ⇒ Object
38 39 40 |
# File 'lib/txt2img.rb', line 38 def height @txt.split(/[\r\n]+/).size end |
#wrap! ⇒ Object
TODO optimize TODO NOT break English word TODO tune the margin and text size
32 33 34 35 36 |
# File 'lib/txt2img.rb', line 32 def wrap! @txt = @txt.split(/[\r\n]+/).map do |line| wrap_by_width(line, width) end * "\n" end |
#write(path) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/txt2img.rb', line 20 def write(path) wrap! image = QuickMagick::Image::solid(width * pointsize + 100, ((height * pointsize) * 1.3).to_i, :white) image.font = font image.pointsize = pointsize image.draw_text(0, 0, txt, :gravity => "center") image.save(path) end |