class Morandi::ImageCaption
Attributes
font[RW]
position[RW]
text[RW]
Public Class Methods
new()
click to toggle source
Calls superclass method
Morandi::ImageOp::new
# File lib/morandi/image-ops.rb, line 110 def initialize() super() end
Public Instance Methods
call(image, pixbuf)
click to toggle source
# 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