aaf-lipstick 4.2.0 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/lipstick/images.rb +1 -0
- data/lib/lipstick/images/email_banner.rb +8 -3
- data/lib/lipstick/images/logo_only_email_banner.rb +132 -0
- data/lib/lipstick/images/processor.rb +20 -3
- data/lib/lipstick/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 78d935ff8ff247803b2bf7580d5284eb3470054e5ee6875be5d024fb1d5ae6fe
|
|
4
|
+
data.tar.gz: 42d1c91bf89f1e294809718641bec4390c178366082b4aa7c362735f6d89b6da
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 531ff037d5f0b6fcbebe46d02eb8bba04c583f42f66a69e5e3982e161762e4906e5a8838f4bfc6bad7752d2b023d48da018985d6b55675cc5e425c7cc5e4a426
|
|
7
|
+
data.tar.gz: 20c246377c4ce1b00eb248351aebce3f1249918dbb3b8988917c4cba187c2c9c5f2f0980d239b6a33ff572da05af33935bef94d37c46aebd0e5a5ace49e646b0
|
data/lib/lipstick/images.rb
CHANGED
|
@@ -28,17 +28,22 @@ module Lipstick
|
|
|
28
28
|
#
|
|
29
29
|
# For image compositing, (x, y) is the position of the top-left corner.
|
|
30
30
|
class EmailBanner
|
|
31
|
-
def initialize(image:, title:, environment
|
|
31
|
+
def initialize(image:, title:, environment:,
|
|
32
|
+
background_color:, resize_to:)
|
|
32
33
|
@title = title
|
|
33
34
|
@environment = environment
|
|
34
35
|
@image = image
|
|
36
|
+
@background_color = background_color
|
|
37
|
+
@resize_to = resize_to
|
|
35
38
|
end
|
|
36
39
|
|
|
37
40
|
def to_png
|
|
41
|
+
bgcolor = @background_color
|
|
42
|
+
|
|
38
43
|
canvas = Magick::ImageList.new
|
|
39
44
|
canvas.new_image(WIDTH, HEIGHT) do |f|
|
|
40
45
|
f.format = 'PNG'
|
|
41
|
-
f.background_color =
|
|
46
|
+
f.background_color = bgcolor
|
|
42
47
|
end
|
|
43
48
|
|
|
44
49
|
annotate_title(canvas)
|
|
@@ -90,7 +95,7 @@ module Lipstick
|
|
|
90
95
|
|
|
91
96
|
def logo
|
|
92
97
|
@logo ||= Magick::Image.read(@image.pathname.to_s).first
|
|
93
|
-
.resize_to_fill(
|
|
98
|
+
.resize_to_fill(@resize_to[0], @resize_to[1])
|
|
94
99
|
end
|
|
95
100
|
|
|
96
101
|
def gap
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rmagick'
|
|
4
|
+
|
|
5
|
+
require 'pry'
|
|
6
|
+
|
|
7
|
+
module Lipstick
|
|
8
|
+
module Images
|
|
9
|
+
# Creates a logo-only email banner, with two elements.
|
|
10
|
+
#
|
|
11
|
+
# 1. Logo, centered vertically and horizontally within the image.
|
|
12
|
+
# 2. Environment string, stamped across the logo.
|
|
13
|
+
#
|
|
14
|
+
# The math here seemed like it would be a lot simpler than the EmailBanner
|
|
15
|
+
# class, but then I went and made it all confusing by bringing trigonometry
|
|
16
|
+
# into it. I promise there was a good reason for doing it.
|
|
17
|
+
class LogoOnlyEmailBanner
|
|
18
|
+
def initialize(image:, environment:, background_color:)
|
|
19
|
+
@environment = environment.upcase
|
|
20
|
+
@image = image
|
|
21
|
+
@background_color = background_color
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def to_png
|
|
25
|
+
bgcolor = @background_color
|
|
26
|
+
|
|
27
|
+
canvas = Magick::ImageList.new
|
|
28
|
+
canvas.new_image(WIDTH, HEIGHT) do |f|
|
|
29
|
+
f.format = 'PNG'
|
|
30
|
+
f.background_color = bgcolor
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
canvas.composite!(logo, logo_x, logo_y, Magick::SrcOverCompositeOp)
|
|
34
|
+
|
|
35
|
+
annotate_environment(canvas)
|
|
36
|
+
|
|
37
|
+
canvas.to_blob
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
WIDTH = 600
|
|
43
|
+
HEIGHT = 150
|
|
44
|
+
MID_Y = HEIGHT / 2
|
|
45
|
+
ANGLE_DEGREES = 10
|
|
46
|
+
ANGLE_RADIANS = Math::PI * ANGLE_DEGREES / 180
|
|
47
|
+
private_constant :WIDTH, :HEIGHT, :MID_Y, :ANGLE_DEGREES, :ANGLE_RADIANS
|
|
48
|
+
|
|
49
|
+
def environment_format
|
|
50
|
+
@environment_format ||= Magick::Draw.new do |title|
|
|
51
|
+
title.font_family = 'ArialB'
|
|
52
|
+
title.font_weight = 900
|
|
53
|
+
title.pointsize = 36
|
|
54
|
+
title.gravity = Magick::ForgetGravity
|
|
55
|
+
title.fill = '#bc2028'
|
|
56
|
+
title.rotation = (-1) * ANGLE_DEGREES
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def blank_environment?
|
|
61
|
+
!@environment&.present?
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def annotate_environment(canvas)
|
|
65
|
+
return if blank_environment?
|
|
66
|
+
|
|
67
|
+
environment_format.annotate(canvas, 0, 0, env_x, env_y, @environment)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def logo
|
|
71
|
+
@logo ||= Magick::Image.read(@image.pathname.to_s).first
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def gap
|
|
75
|
+
@gap ||= environment_format.get_type_metrics('AAF').width
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def logo_w
|
|
79
|
+
logo.bounding_box.width
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# x position to vertically center logo
|
|
83
|
+
def logo_x
|
|
84
|
+
((WIDTH - logo.bounding_box.width) / 2).round
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# y position to vertically center logo
|
|
88
|
+
def logo_y
|
|
89
|
+
((HEIGHT - logo.bounding_box.height) / 2).round
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def env_metrics
|
|
93
|
+
return OpenStruct.new(width: 0, height: 0) if blank_environment?
|
|
94
|
+
|
|
95
|
+
environment_format.get_type_metrics(@environment)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def env_x
|
|
99
|
+
m = env_metrics
|
|
100
|
+
|
|
101
|
+
# The horizontal width of the environment text is found by:
|
|
102
|
+
# w cos(Θ) + h sin(Θ)
|
|
103
|
+
#
|
|
104
|
+
# w = text width
|
|
105
|
+
# h = text ascent
|
|
106
|
+
# Θ = angle of text rotation
|
|
107
|
+
#
|
|
108
|
+
# Contrary to the description in `EmailBanner`, since we're upper
|
|
109
|
+
# casing the environment string here, we don't need to worry about text
|
|
110
|
+
# descent.
|
|
111
|
+
w = Math.cos(ANGLE_RADIANS) * m.width +
|
|
112
|
+
Math.sin(ANGLE_RADIANS) * m.ascent
|
|
113
|
+
|
|
114
|
+
# We center that the same as for `logo_x`
|
|
115
|
+
((WIDTH - w) / 2).round
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def env_y
|
|
119
|
+
m = env_metrics
|
|
120
|
+
|
|
121
|
+
# The horizontal width of the environment text is found by:
|
|
122
|
+
# w sin(Θ) + h cos(Θ)
|
|
123
|
+
h = Math.sin(ANGLE_RADIANS) * m.width +
|
|
124
|
+
Math.cos(ANGLE_RADIANS) * m.ascent
|
|
125
|
+
|
|
126
|
+
# We use addition here instead of the usual subtraction, as the text
|
|
127
|
+
# moves in the upward direction from the position we set.
|
|
128
|
+
((HEIGHT + h) / 2).round
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
@@ -16,11 +16,28 @@ module Lipstick
|
|
|
16
16
|
end
|
|
17
17
|
# rubocop:enable Security/Eval
|
|
18
18
|
|
|
19
|
-
def email_banner(image: 'logo.png', title:, environment
|
|
19
|
+
def email_banner(image: 'logo.png', title:, environment:, **kwargs)
|
|
20
20
|
@context.depend_on_asset(image)
|
|
21
21
|
asset = @context.environment.find_asset(image)
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
|
|
23
|
+
EmailBanner.new(
|
|
24
|
+
image: asset,
|
|
25
|
+
title: title,
|
|
26
|
+
environment: environment,
|
|
27
|
+
background_color: kwargs[:background_color] || '#2A3685',
|
|
28
|
+
resize_to: kwargs[:resize_to] || [78, 78]
|
|
29
|
+
).to_png
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def logo_only_email_banner(image: 'logo.png', environment:, **kwargs)
|
|
33
|
+
@context.depend_on_asset(image)
|
|
34
|
+
asset = @context.environment.find_asset(image)
|
|
35
|
+
|
|
36
|
+
LogoOnlyEmailBanner.new(
|
|
37
|
+
image: asset,
|
|
38
|
+
environment: environment,
|
|
39
|
+
background_color: kwargs[:background_color] || '#2A3685'
|
|
40
|
+
).to_png
|
|
24
41
|
end
|
|
25
42
|
end
|
|
26
43
|
|
data/lib/lipstick/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: aaf-lipstick
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.
|
|
4
|
+
version: 4.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shaun Mangelsdorf
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-
|
|
11
|
+
date: 2019-12-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: erubis
|
|
@@ -324,6 +324,7 @@ files:
|
|
|
324
324
|
- lib/lipstick/helpers/sortable_helper.rb
|
|
325
325
|
- lib/lipstick/images.rb
|
|
326
326
|
- lib/lipstick/images/email_banner.rb
|
|
327
|
+
- lib/lipstick/images/logo_only_email_banner.rb
|
|
327
328
|
- lib/lipstick/images/processor.rb
|
|
328
329
|
- lib/lipstick/sortable.rb
|
|
329
330
|
- lib/lipstick/version.rb
|
|
@@ -346,8 +347,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
346
347
|
- !ruby/object:Gem::Version
|
|
347
348
|
version: '0'
|
|
348
349
|
requirements: []
|
|
349
|
-
|
|
350
|
-
rubygems_version: 2.5.2.3
|
|
350
|
+
rubygems_version: 3.0.3
|
|
351
351
|
signing_key:
|
|
352
352
|
specification_version: 4
|
|
353
353
|
summary: A gem for applying AAF branding to our services
|