jekyll-og-image 1.0.5 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec_status +7 -5
- data/README.md +45 -0
- data/examples/3.png +0 -0
- data/examples/4.png +0 -0
- data/lib/jekyll_og_image/config.rb +32 -3
- data/lib/jekyll_og_image/element/base.rb +8 -0
- data/lib/jekyll_og_image/element/canvas.rb +13 -2
- data/lib/jekyll_og_image/element/image.rb +2 -10
- data/lib/jekyll_og_image/generator.rb +29 -14
- data/lib/jekyll_og_image/version.rb +1 -1
- metadata +9 -8
- data/jekyll-og-image.gemspec +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d7ab3e37756339d3435bb110e3e612476888bea4ba020115ebc25e45708e9d5
|
4
|
+
data.tar.gz: 2940f89d8f183a158d8cb4da4a0ee5859ae1f414acf272ad5928c7302ad2f494
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 163fc1a8a585391ab60f6e233291497275b2902a0d13e397211af6a610606ad510e33e8d98fbb153ad1ee943cd86d00e5bcf359527a52c51c05bd51b97774a4e
|
7
|
+
data.tar.gz: 946b88643e7b584ab44114e7fc6e94578b53ccfe156c5758b93ae93099b2e442f13edc10c23c5541215ba229fa2b76fa69af8dcb186ef777e5745fb5c48b0573
|
data/.rspec_status
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
example_id
|
2
|
-
|
3
|
-
./spec/
|
4
|
-
./spec/
|
5
|
-
./spec/
|
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,6 +61,51 @@ og_image:
|
|
61
61
|
|
62
62
|
![Example 1](examples/1.png)
|
63
63
|
|
64
|
+
### Background Color and Text Color
|
65
|
+
|
66
|
+
```yaml
|
67
|
+
og_image:
|
68
|
+
output_dir: "/assets/og"
|
69
|
+
image: "/assets/images/igor.jpeg"
|
70
|
+
canvas:
|
71
|
+
background_color: "#F9E065"
|
72
|
+
header:
|
73
|
+
font_family: "Roboto, Bold"
|
74
|
+
color: "#333333"
|
75
|
+
content:
|
76
|
+
font_family: "Roboto, Regular"
|
77
|
+
color: "#333333"
|
78
|
+
force: false
|
79
|
+
domain: "igor.works"
|
80
|
+
border_bottom:
|
81
|
+
width: 50
|
82
|
+
fill:
|
83
|
+
- "#002B7F"
|
84
|
+
- "#FCD116"
|
85
|
+
- "#CE1126"
|
86
|
+
```
|
87
|
+
|
88
|
+
![Example 3](examples/3.png)
|
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)
|
64
109
|
|
65
110
|
|
66
111
|
## Contributing
|
data/examples/3.png
ADDED
Binary file
|
data/examples/4.png
ADDED
Binary file
|
@@ -5,11 +5,36 @@ require "anyway_config"
|
|
5
5
|
class JekyllOgImage::Config < Anyway::Config
|
6
6
|
attr_config output_dir: "assets/images/og"
|
7
7
|
attr_config force: false
|
8
|
+
attr_config verbose: false
|
9
|
+
attr_config canvas: {
|
10
|
+
background_color: "#FFFFFF",
|
11
|
+
background_image: nil
|
12
|
+
}
|
13
|
+
attr_config header: {
|
14
|
+
font_family: "Helvetica, Bold",
|
15
|
+
color: "#2f313d"
|
16
|
+
}
|
17
|
+
attr_config content: {
|
18
|
+
font_family: "Helvetica, Regular",
|
19
|
+
color: "#535358"
|
20
|
+
}
|
8
21
|
attr_config :image
|
9
22
|
attr_config :domain
|
10
|
-
attr_config border_bottom
|
11
|
-
|
12
|
-
|
23
|
+
attr_config :border_bottom
|
24
|
+
|
25
|
+
coerce_types canvas: {
|
26
|
+
background_color: { type: :string },
|
27
|
+
background_image: { type: :string }
|
28
|
+
}
|
29
|
+
|
30
|
+
coerce_types header: {
|
31
|
+
font_family: { type: :string },
|
32
|
+
color: { type: :string }
|
33
|
+
}
|
34
|
+
|
35
|
+
coerce_types content: {
|
36
|
+
font_family: { type: :string },
|
37
|
+
color: { type: :string }
|
13
38
|
}
|
14
39
|
|
15
40
|
coerce_types image: { type: :string }
|
@@ -18,4 +43,8 @@ class JekyllOgImage::Config < Anyway::Config
|
|
18
43
|
width: { type: :integer },
|
19
44
|
fill: { type: :string, array: true }
|
20
45
|
}
|
46
|
+
|
47
|
+
def margin_bottom
|
48
|
+
80 + (border_bottom&.fetch("width", 0) || 0)
|
49
|
+
end
|
21
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,
|
7
|
-
@canvas = Vips::Image.black(width, height).ifthenelse([ 0, 0, 0 ], hex_to_rgb(
|
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
|
@@ -15,10 +15,10 @@ class JekyllOgImage::Generator < Jekyll::Generator
|
|
15
15
|
path = File.join(site.config["source"], base_path, "#{post.data['slug']}.png")
|
16
16
|
|
17
17
|
if !File.exist?(path) || JekyllOgImage.config.force?
|
18
|
-
Jekyll.logger.info "Jekyll Og Image:", "Generating image #{path}"
|
18
|
+
Jekyll.logger.info "Jekyll Og Image:", "Generating image #{path}" if JekyllOgImage.config.verbose?
|
19
19
|
generate_image_for_post(site, post, path)
|
20
20
|
else
|
21
|
-
Jekyll.logger.info "Jekyll Og Image:", "Skipping image generation #{path} as it already exists."
|
21
|
+
Jekyll.logger.info "Jekyll Og Image:", "Skipping image generation #{path} as it already exists." if JekyllOgImage.config.verbose?
|
22
22
|
end
|
23
23
|
|
24
24
|
post.data["image"] ||= {
|
@@ -35,11 +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
|
-
|
39
|
-
.
|
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
|
+
|
42
|
+
canvas = JekyllOgImage::Element::Canvas.new(1200, 600,
|
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"],
|
40
49
|
position: :bottom,
|
41
50
|
fill: JekyllOgImage.config.border_bottom["fill"]
|
42
51
|
)
|
52
|
+
end
|
43
53
|
|
44
54
|
if JekyllOgImage.config.image
|
45
55
|
canvas = canvas.image(
|
@@ -53,34 +63,39 @@ class JekyllOgImage::Generator < Jekyll::Generator
|
|
53
63
|
|
54
64
|
canvas = canvas.text(post.data["title"],
|
55
65
|
width: JekyllOgImage.config.image ? 870 : 1040,
|
56
|
-
color: "
|
66
|
+
color: JekyllOgImage.config.header["color"],
|
57
67
|
dpi: 400,
|
58
|
-
font: "
|
68
|
+
font: JekyllOgImage.config.header["font_family"]
|
59
69
|
) { |_canvas, _text| { x: 80, y: 100 } }
|
60
70
|
|
61
71
|
canvas = canvas.text(date,
|
62
72
|
gravity: :sw,
|
63
|
-
color: "
|
73
|
+
color: JekyllOgImage.config.content["color"],
|
64
74
|
dpi: 150,
|
65
|
-
font: "
|
66
|
-
) { |_canvas, _text| { x: 80, y: post.data["tags"].any? ?
|
75
|
+
font: JekyllOgImage.config.content["font_family"]
|
76
|
+
) { |_canvas, _text| { x: 80, y: post.data["tags"].any? ? JekyllOgImage.config.margin_bottom + 50 : JekyllOgImage.config.margin_bottom } }
|
67
77
|
|
68
78
|
if post.data["tags"].any?
|
69
79
|
tags = post.data["tags"].map { |tag| "##{tag}" }.join(" ")
|
70
80
|
|
71
81
|
canvas = canvas.text(tags,
|
72
82
|
gravity: :sw,
|
73
|
-
color: "
|
83
|
+
color: JekyllOgImage.config.content["color"],
|
74
84
|
dpi: 150,
|
75
|
-
font: "
|
76
|
-
) { |_canvas, _text| { x: 80, y:
|
85
|
+
font: JekyllOgImage.config.content["font_family"]
|
86
|
+
) { |_canvas, _text| { x: 80, y: JekyllOgImage.config.margin_bottom } }
|
77
87
|
end
|
78
88
|
|
79
89
|
if JekyllOgImage.config.domain
|
80
|
-
canvas = canvas.text(JekyllOgImage.config.domain,
|
90
|
+
canvas = canvas.text(JekyllOgImage.config.domain,
|
91
|
+
gravity: :se,
|
92
|
+
color: JekyllOgImage.config.content["color"],
|
93
|
+
dpi: 150,
|
94
|
+
font: JekyllOgImage.config.content["font_family"]
|
95
|
+
) do |_canvas, _text|
|
81
96
|
{
|
82
97
|
x: 80,
|
83
|
-
y: post.data["tags"].any? ?
|
98
|
+
y: post.data["tags"].any? ? JekyllOgImage.config.margin_bottom + 50 : JekyllOgImage.config.margin_bottom
|
84
99
|
}
|
85
100
|
end
|
86
101
|
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.0
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Alexandrov
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
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
|
@@ -86,7 +86,7 @@ dependencies:
|
|
86
86
|
- - "<"
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '5.0'
|
89
|
-
description:
|
89
|
+
description:
|
90
90
|
email:
|
91
91
|
- igor.alexandrov@gmail.com
|
92
92
|
executables: []
|
@@ -102,7 +102,8 @@ files:
|
|
102
102
|
- Rakefile
|
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
|
@@ -118,7 +119,7 @@ licenses:
|
|
118
119
|
- MIT
|
119
120
|
metadata:
|
120
121
|
homepage_uri: https://github.com/igor-alexandrov/jekyll-og-image
|
121
|
-
post_install_message:
|
122
|
+
post_install_message:
|
122
123
|
rdoc_options: []
|
123
124
|
require_paths:
|
124
125
|
- lib
|
@@ -133,8 +134,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
134
|
- !ruby/object:Gem::Version
|
134
135
|
version: '0'
|
135
136
|
requirements: []
|
136
|
-
rubygems_version: 3.5.
|
137
|
-
signing_key:
|
137
|
+
rubygems_version: 3.5.3
|
138
|
+
signing_key:
|
138
139
|
specification_version: 4
|
139
140
|
summary: Jekyll plugin to generate GitHub-style open graph images
|
140
141
|
test_files: []
|
data/jekyll-og-image.gemspec
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "lib/jekyll_og_image/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "jekyll-og-image"
|
7
|
-
spec.version = JekyllOgImage::VERSION
|
8
|
-
spec.authors = [ "Igor Alexandrov" ]
|
9
|
-
spec.email = [ "igor.alexandrov@gmail.com" ]
|
10
|
-
|
11
|
-
spec.summary = "Jekyll plugin to generate GitHub-style open graph images"
|
12
|
-
spec.homepage = "https://github.com/igor-alexandrov/jekyll-og-image"
|
13
|
-
spec.license = "MIT"
|
14
|
-
spec.required_ruby_version = ">= 3.2.0"
|
15
|
-
|
16
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
-
|
18
|
-
# Specify which files should be added to the gem when it is released.
|
19
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
-
spec.files = Dir.chdir(__dir__) do
|
21
|
-
`git ls-files -z`.split("\x0").reject do |f|
|
22
|
-
(File.expand_path(f) == __FILE__) ||
|
23
|
-
f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
spec.require_paths = [ "lib" ]
|
28
|
-
|
29
|
-
spec.add_dependency "jekyll-seo-tag", "~> 2.8"
|
30
|
-
spec.add_dependency "zeitwerk", "~> 2.6"
|
31
|
-
spec.add_dependency "anyway_config", "~> 2.6"
|
32
|
-
spec.add_dependency "ruby-vips", "~> 2.2.0"
|
33
|
-
spec.add_runtime_dependency "jekyll", ">= 3.4", "< 5.0"
|
34
|
-
end
|