lib/lipstick/images/email_banner.rb in aaf-lipstick-1.1.0 vs lib/lipstick/images/email_banner.rb in aaf-lipstick-2.0.0
- old
+ new
@@ -1,5 +1,6 @@
+# frozen_string_literal: true
require 'rmagick'
module Lipstick
module Images
# Creates an AAF standard email banner, with three elements, positioned as
@@ -34,11 +35,11 @@
def to_png
canvas = Magick::ImageList.new
canvas.new_image(WIDTH, HEIGHT) do |f|
f.format = 'PNG'
- f.background_color = '#495666'
+ f.background_color = '#2A3685'
end
annotate_title(canvas)
annotate_environment(canvas)
@@ -70,22 +71,26 @@
title.gravity = Magick::ForgetGravity
title.fill = '#dd7727'
end
end
+ def blank_environment?
+ !@environment&.present?
+ end
+
def annotate_title(canvas)
title_format.annotate(canvas, 0, 0, title_x, title_y, @title)
end
def annotate_environment(canvas)
+ return if blank_environment?
environment_format.annotate(canvas, 0, 0, env_x, env_y, @environment)
end
def logo
- asset = Rails.application.assets.find_asset(@image)
- @logo ||= Magick::Image.read(asset.pathname.to_s).first
- .resize_to_fill(150, 80)
+ @logo ||= Magick::Image.read(@image.pathname.to_s).first
+ .resize_to_fill(78, 78)
end
def gap
@gap ||= environment_format.get_type_metrics('AAF').width
end
@@ -106,9 +111,10 @@
def title_metrics
title_format.get_type_metrics(@title)
end
def env_metrics
+ return OpenStruct.new(width: 0, height: 0) if blank_environment?
environment_format.get_type_metrics(@environment)
end
# Halve the total margin to horizontally center the whole content area.
def margin_x