Class: Morandi::ImageCaption
- Defined in:
- lib/morandi/image-ops.rb
Instance Attribute Summary collapse
-
#font ⇒ Object
Returns the value of attribute font.
-
#position ⇒ Object
Returns the value of attribute position.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
- #call(image, pixbuf) ⇒ Object
-
#initialize ⇒ ImageCaption
constructor
A new instance of ImageCaption.
Methods inherited from ImageOp
Constructor Details
#initialize ⇒ ImageCaption
Returns a new instance of ImageCaption.
110 111 112 |
# File 'lib/morandi/image-ops.rb', line 110 def initialize() super() end |
Instance Attribute Details
#font ⇒ Object
Returns the value of attribute font.
109 110 111 |
# File 'lib/morandi/image-ops.rb', line 109 def font @font end |
#position ⇒ Object
Returns the value of attribute position.
109 110 111 |
# File 'lib/morandi/image-ops.rb', line 109 def position @position end |
#text ⇒ Object
Returns the value of attribute text.
109 110 111 |
# File 'lib/morandi/image-ops.rb', line 109 def text @text end |
Instance Method Details
#call(image, pixbuf) ⇒ Object
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 |
# File 'lib/morandi/image-ops.rb', line 123 def call(image, pixbuf) @pixbuf = pixbuf surface = Cairo::ImageSurface.new(:rgb24, pixbuf.width, pixbuf.height) cr = Cairo::Context.new(surface) cr.save do cr.set_source_pixbuf(pixbuf) #cr.rectangle(0, 0, pixbuf.width, pixbuf.height) cr.paint(1.0) cr.translate(*self.position) layout = cr.create_pango_layout layout.set_text(self.text) fd = Pango::FontDescription.new(self.font) layout.font_description = fd layout.set_width((pixbuf.width - self.position[0] - 100)*Pango::SCALE) layout.context_changed ink, _ = layout.pixel_extents cr.set_source_rgba(0, 0, 0, 0.3) cr.rectangle(-25, -25, ink.width + 50, ink.height + 50) cr.fill cr.set_source_rgb(1, 1, 1) cr.show_pango_layout(layout) end final_pb = surface.to_pixbuf cr.destroy surface.destroy return final_pb end |