Class: JekyllOgImage::Element::Canvas
- Inherits:
-
Base
- Object
- Base
- JekyllOgImage::Element::Canvas
- Defined in:
- lib/jekyll_og_image/element/canvas.rb
Instance Method Summary collapse
- #border(width, **opts, &block) ⇒ Object
- #image(source, **opts, &block) ⇒ Object
-
#initialize(width, height, background_color: "#ffffff", background_image: nil) ⇒ Canvas
constructor
A new instance of Canvas.
- #save(filename) ⇒ Object
- #text(message, **opts, &block) ⇒ Object
Constructor Details
#initialize(width, height, background_color: "#ffffff", background_image: nil) ⇒ Canvas
Returns a new instance of Canvas.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/jekyll_og_image/element/canvas.rb', line 6 def initialize(width, height, background_color: "#ffffff", background_image: nil) @canvas = Vips::Image.black(width, height).ifthenelse([ 0, 0, 0 ], hex_to_rgb(background_color)) if background_image = Vips::Image.new_from_buffer(background_image, "") ratio = calculate_ratio(, width, height, :max) = .resize(ratio) @canvas = @canvas.composite(, :over, x: [ 0 ], y: [ 0 ]).flatten end @canvas end |
Instance Method Details
#border(width, **opts, &block) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/jekyll_og_image/element/canvas.rb', line 35 def border(width, **opts, &block) border = JekyllOgImage::Element::Border.new(width, **opts) @canvas = border.apply_to(@canvas, &block) self end |
#image(source, **opts, &block) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/jekyll_og_image/element/canvas.rb', line 21 def image(source, **opts, &block) image = JekyllOgImage::Element::Image.new(source, **opts) @canvas = image.apply_to(@canvas, &block) self end |
#save(filename) ⇒ Object
42 43 44 |
# File 'lib/jekyll_og_image/element/canvas.rb', line 42 def save(filename) @canvas.write_to_file(filename) end |
#text(message, **opts, &block) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/jekyll_og_image/element/canvas.rb', line 28 def text(, **opts, &block) text = JekyllOgImage::Element::Text.new(, **opts) @canvas = text.apply_to(@canvas, &block) self end |