Class: Txt2img::Txt
- Inherits:
-
Object
- Object
- Txt2img::Txt
- Defined in:
- lib/txt2img.rb
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, font = nil, width = 20, pointsize = 30) ⇒ Txt
constructor
A new instance of Txt.
-
#wrap! ⇒ Object
TODO optimize.
- #write(path) ⇒ Object
Constructor Details
#initialize(txt, font = nil, width = 20, pointsize = 30) ⇒ Txt
Returns a new instance of Txt.
9 10 11 12 13 14 |
# File 'lib/txt2img.rb', line 9 def initialize(txt, font = nil, width = 20, pointsize = 30) @txt = txt @font ||= File.("../../fonts/microhei.ttc", __FILE__) @width ||= 20 @pointsize ||= 30 end |
Instance Attribute Details
#font ⇒ Object
Returns the value of attribute font.
7 8 9 |
# File 'lib/txt2img.rb', line 7 def font @font end |
#pointsize ⇒ Object
Returns the value of attribute pointsize.
7 8 9 |
# File 'lib/txt2img.rb', line 7 def pointsize @pointsize end |
#txt ⇒ Object
Returns the value of attribute txt.
7 8 9 |
# File 'lib/txt2img.rb', line 7 def txt @txt end |
#width ⇒ Object
Returns the value of attribute width.
7 8 9 |
# File 'lib/txt2img.rb', line 7 def width @width end |
Instance Method Details
#height ⇒ Object
30 31 32 |
# File 'lib/txt2img.rb', line 30 def height @txt.split(/[\r\n]+/).size end |
#wrap! ⇒ Object
TODO optimize
26 27 28 |
# File 'lib/txt2img.rb', line 26 def wrap! @txt = @txt.split(/[\r\n]+/).map{|x| x.scan(/.{1,#{width}}/).join("\n")}.join("\n") end |
#write(path) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/txt2img.rb', line 16 def write(path) wrap! image = QuickMagick::Image::solid(width * pointsize + 100, ((height * pointsize) * 1.3).to_i, :white) image.font = font image.pointsize = 40 image.draw_text(0, 0, txt, :gravity => "center") image.save(path) end |