Class: Lipstick::Images::EmailBanner
- Inherits:
-
Object
- Object
- Lipstick::Images::EmailBanner
- Defined in:
- lib/lipstick/images/email_banner.rb
Overview
Creates an AAF standard email banner, with three elements, positioned as follows:
-
AAF Logo. Vertically centered and left-aligned within the content box, and with a blank space to the right.
-
Application title. Vertically centered, and left-aligned to the logo’s right margin.
-
Environment string. Positioned 10 pixels below the app title, and left-aligned to the logo’s right margin.
The “box” containing these three elements is horizontally centered in the resulting image.
Text metrics work as follows, using “Alimony” as the example word:
-
(x, y) is the position of the bottom left tip of ‘A’
-
‘ascent` is the letter height from that point (i.e. the height of ’A’)
-
‘descent` is a negative value; the letter height below that point (i.e. the height of the ’tail’ of ‘y’)
-
‘height` is greater than `(ascent - descent)`, making it useless for our purposes here.
For image compositing, (x, y) is the position of the top-left corner.
Instance Method Summary collapse
-
#initialize(image:, title:, environment:, background_color:, resize_to:) ⇒ EmailBanner
constructor
A new instance of EmailBanner.
- #to_png ⇒ Object
Constructor Details
#initialize(image:, title:, environment:, background_color:, resize_to:) ⇒ EmailBanner
Returns a new instance of EmailBanner.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/lipstick/images/email_banner.rb', line 29 def initialize(image:, title:, environment:, background_color:, resize_to:) require 'rmagick' @title = title @environment = environment @image = image @background_color = background_color @resize_to = resize_to end |
Instance Method Details
#to_png ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/lipstick/images/email_banner.rb', line 40 def to_png bgcolor = @background_color canvas = Magick::ImageList.new canvas.new_image(WIDTH, HEIGHT) do |f| f.format = 'PNG' f.background_color = bgcolor end annotate_title(canvas) annotate_environment(canvas) canvas.composite!(logo, logo_x, logo_y, Magick::SrcOverCompositeOp) canvas.to_blob end |