jekyll-og-image 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b61ed8f290ff7d539d5797f7e176821c7467cf1e5c2405e54960909663271ef5
4
- data.tar.gz: 300123301cf7fc2dc403cc8254181772983f036cb8a06e7e23374fda7861d62c
3
+ metadata.gz: 3d7ab3e37756339d3435bb110e3e612476888bea4ba020115ebc25e45708e9d5
4
+ data.tar.gz: 2940f89d8f183a158d8cb4da4a0ee5859ae1f414acf272ad5928c7302ad2f494
5
5
  SHA512:
6
- metadata.gz: 6a29185631359c3b89faddc2b54187bbfd663b762c6533eb5909270e78320c04f313193ddd4c3e33652946865ef486b7bfaefbb941637a965d8fc02f8f6560b4
7
- data.tar.gz: 83fa74112ac6747aa11a402913b6cd736c828f318b8a08ddf342d7aac8212a367b9c7028378fe681dbb8725dd44a6fcfe3ec379beb9e999e9e105cc6d52adb61
6
+ metadata.gz: 163fc1a8a585391ab60f6e233291497275b2902a0d13e397211af6a610606ad510e33e8d98fbb153ad1ee943cd86d00e5bcf359527a52c51c05bd51b97774a4e
7
+ data.tar.gz: 946b88643e7b584ab44114e7fc6e94578b53ccfe156c5758b93ae93099b2e442f13edc10c23c5541215ba229fa2b76fa69af8dcb186ef777e5745fb5c48b0573
data/.rspec_status CHANGED
@@ -1,5 +1,7 @@
1
- example_id | status | run_time |
2
- ----------------------------------- | ------ | --------------- |
3
- ./spec/jekyll_og_image_spec.rb[1:1] | passed | 0.01708 seconds |
4
- ./spec/jekyll_og_image_spec.rb[1:2] | passed | 0.27293 seconds |
5
- ./spec/jekyll_og_image_spec.rb[1:3] | passed | 0.06846 seconds |
1
+ example_id | status | run_time |
2
+ ---------------------------------------------- | ------ | --------------- |
3
+ ./spec/jekyll_og_image/config_spec.rb[1:1:1:1] | passed | 0.00069 seconds |
4
+ ./spec/jekyll_og_image/config_spec.rb[1:1:2:1] | passed | 0.00014 seconds |
5
+ ./spec/jekyll_og_image/version_spec.rb[1:1] | passed | 0.00031 seconds |
6
+ ./spec/jekyll_og_image_spec.rb[1:1] | passed | 0.26017 seconds |
7
+ ./spec/jekyll_og_image_spec.rb[1:2] | passed | 0.04281 seconds |
data/README.md CHANGED
@@ -61,7 +61,7 @@ og_image:
61
61
 
62
62
  ![Example 1](examples/1.png)
63
63
 
64
- ### Background Color and Text Colors
64
+ ### Background Color and Text Color
65
65
 
66
66
  ```yaml
67
67
  og_image:
@@ -78,7 +78,7 @@ og_image:
78
78
  force: false
79
79
  domain: "igor.works"
80
80
  border_bottom:
81
- width: 20
81
+ width: 50
82
82
  fill:
83
83
  - "#002B7F"
84
84
  - "#FCD116"
@@ -87,6 +87,26 @@ og_image:
87
87
 
88
88
  ![Example 3](examples/3.png)
89
89
 
90
+ ### Background Image
91
+
92
+ ```yaml
93
+ og_image:
94
+ output_dir: "/assets/og"
95
+ image: "/assets/images/igor.jpeg"
96
+ canvas:
97
+ background_image: "/assets/images/bc_3.jpg"
98
+ header:
99
+ font_family: "Roboto, Bold"
100
+ color: "#333333"
101
+ content:
102
+ font_family: "Roboto, Bold"
103
+ color: "#333333"
104
+ force: false
105
+ domain: "igor.works"
106
+ ```
107
+
108
+ ![Example 4](examples/4.png)
109
+
90
110
 
91
111
  ## Contributing
92
112
 
data/examples/3.png CHANGED
Binary file
data/examples/4.png ADDED
Binary file
@@ -7,7 +7,8 @@ class JekyllOgImage::Config < Anyway::Config
7
7
  attr_config force: false
8
8
  attr_config verbose: false
9
9
  attr_config canvas: {
10
- background_color: "#FFFFFF"
10
+ background_color: "#FFFFFF",
11
+ background_image: nil
11
12
  }
12
13
  attr_config header: {
13
14
  font_family: "Helvetica, Bold",
@@ -19,13 +20,11 @@ class JekyllOgImage::Config < Anyway::Config
19
20
  }
20
21
  attr_config :image
21
22
  attr_config :domain
22
- attr_config border_bottom: {
23
- width: 20,
24
- fill: [ "#211F1F", "#F4CBB2", "#AD5C51", "#9CDAF1", "#7DBBE6" ]
25
- }
23
+ attr_config :border_bottom
26
24
 
27
25
  coerce_types canvas: {
28
- background_color: { type: :string }
26
+ background_color: { type: :string },
27
+ background_image: { type: :string }
29
28
  }
30
29
 
31
30
  coerce_types header: {
@@ -44,4 +43,8 @@ class JekyllOgImage::Config < Anyway::Config
44
43
  width: { type: :integer },
45
44
  fill: { type: :string, array: true }
46
45
  }
46
+
47
+ def margin_bottom
48
+ 80 + (border_bottom&.fetch("width", 0) || 0)
49
+ end
47
50
  end
@@ -22,6 +22,14 @@ class JekyllOgImage::Element::Base
22
22
  end
23
23
  end
24
24
 
25
+ def calculate_ratio(image, width, height, mode)
26
+ if mode == :min
27
+ [ width.to_f / image.width, height.to_f / image.height ].min
28
+ else
29
+ [ width.to_f / image.width, height.to_f / image.height ].max
30
+ end
31
+ end
32
+
25
33
  def composite_with_gravity(canvas, overlay, x, y)
26
34
  if gravity_nw?
27
35
  canvas.composite(overlay, :over, x: [ x ], y: [ y ]).flatten
@@ -3,8 +3,19 @@
3
3
  require "vips"
4
4
 
5
5
  class JekyllOgImage::Element::Canvas < JekyllOgImage::Element::Base
6
- def initialize(width, height, color: "#ffffff")
7
- @canvas = Vips::Image.black(width, height).ifthenelse([ 0, 0, 0 ], hex_to_rgb(color))
6
+ def initialize(width, height, background_color: "#ffffff", background_image: nil)
7
+ @canvas = Vips::Image.black(width, height).ifthenelse([ 0, 0, 0 ], hex_to_rgb(background_color))
8
+
9
+ if background_image
10
+ overlay = Vips::Image.new_from_buffer(background_image, "")
11
+
12
+ ratio = calculate_ratio(overlay, width, height, :max)
13
+ overlay = overlay.resize(ratio)
14
+
15
+ @canvas = @canvas.composite(overlay, :over, x: [ 0 ], y: [ 0 ]).flatten
16
+ end
17
+
18
+ @canvas
8
19
  end
9
20
 
10
21
  def image(source, **opts, &block)
@@ -15,13 +15,13 @@ class JekyllOgImage::Element::Image < JekyllOgImage::Element::Base
15
15
  image = Vips::Image.new_from_buffer(@source, "")
16
16
  image = round_corners(image) if @radius
17
17
 
18
- result = block.call(canvas, image) if block_given?
19
-
20
18
  if @width && @height
21
19
  ratio = calculate_ratio(image, @width, @height, :min)
22
20
  image = image.resize(ratio)
23
21
  end
24
22
 
23
+ result = block.call(canvas, image) if block_given?
24
+
25
25
  x, y = result ? [ result.fetch(:x, 0), result.fetch(:y, 0) ] : [ 0, 0 ]
26
26
 
27
27
  composite_with_gravity(canvas, image, x, y)
@@ -53,12 +53,4 @@ class JekyllOgImage::Element::Image < JekyllOgImage::Element::Base
53
53
  mask = Vips::Image.new_from_buffer(mask, "")
54
54
  image.bandjoin mask[3]
55
55
  end
56
-
57
- def calculate_ratio(image, width, height, mode)
58
- if mode == :min
59
- [ width.to_f / image.width, height.to_f / image.height ].min
60
- else
61
- [ width.to_f / image.width, height.to_f / image.height ].max
62
- end
63
- end
64
56
  end
@@ -35,13 +35,21 @@ class JekyllOgImage::Generator < Jekyll::Generator
35
35
  def generate_image_for_post(site, post, path)
36
36
  date = post.date.strftime("%B %d, %Y")
37
37
 
38
+ background_image = if JekyllOgImage.config.canvas["background_image"]
39
+ File.read(File.join(site.config["source"], JekyllOgImage.config.canvas["background_image"]))
40
+ end
41
+
38
42
  canvas = JekyllOgImage::Element::Canvas.new(1200, 600,
39
- color: JekyllOgImage.config.canvas["background_color"]
40
- )
41
- .border(JekyllOgImage.config.border_bottom["width"],
43
+ background_color: JekyllOgImage.config.canvas["background_color"],
44
+ background_image: background_image
45
+ )
46
+
47
+ if JekyllOgImage.config.border_bottom
48
+ canvas = canvas.border(JekyllOgImage.config.border_bottom["width"],
42
49
  position: :bottom,
43
50
  fill: JekyllOgImage.config.border_bottom["fill"]
44
51
  )
52
+ end
45
53
 
46
54
  if JekyllOgImage.config.image
47
55
  canvas = canvas.image(
@@ -65,7 +73,7 @@ class JekyllOgImage::Generator < Jekyll::Generator
65
73
  color: JekyllOgImage.config.content["color"],
66
74
  dpi: 150,
67
75
  font: JekyllOgImage.config.content["font_family"]
68
- ) { |_canvas, _text| { x: 80, y: post.data["tags"].any? ? 150 : 100 } }
76
+ ) { |_canvas, _text| { x: 80, y: post.data["tags"].any? ? JekyllOgImage.config.margin_bottom + 50 : JekyllOgImage.config.margin_bottom } }
69
77
 
70
78
  if post.data["tags"].any?
71
79
  tags = post.data["tags"].map { |tag| "##{tag}" }.join(" ")
@@ -75,7 +83,7 @@ class JekyllOgImage::Generator < Jekyll::Generator
75
83
  color: JekyllOgImage.config.content["color"],
76
84
  dpi: 150,
77
85
  font: JekyllOgImage.config.content["font_family"]
78
- ) { |_canvas, _text| { x: 80, y: 100 } }
86
+ ) { |_canvas, _text| { x: 80, y: JekyllOgImage.config.margin_bottom } }
79
87
  end
80
88
 
81
89
  if JekyllOgImage.config.domain
@@ -87,7 +95,7 @@ class JekyllOgImage::Generator < Jekyll::Generator
87
95
  ) do |_canvas, _text|
88
96
  {
89
97
  x: 80,
90
- y: post.data["tags"].any? ? 150 : 100
98
+ y: post.data["tags"].any? ? JekyllOgImage.config.margin_bottom + 50 : JekyllOgImage.config.margin_bottom
91
99
  }
92
100
  end
93
101
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllOgImage
4
- VERSION = "1.1.0"
4
+ VERSION = "1.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-og-image
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Alexandrov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-13 00:00:00.000000000 Z
11
+ date: 2024-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll-seo-tag
@@ -103,6 +103,7 @@ files:
103
103
  - examples/1.png
104
104
  - examples/2.png
105
105
  - examples/3.png
106
+ - examples/4.png
106
107
  - lib/jekyll-og-image.rb
107
108
  - lib/jekyll_og_image.rb
108
109
  - lib/jekyll_og_image/config.rb