jekyll-responsive-magick 1.1.1 → 1.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 +4 -4
- data/lib/jekyll-responsive-magick.rb +102 -54
- metadata +8 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2905a164041aead23497b61c323bb1e5403b0399e480b093907f48dae526f97
|
4
|
+
data.tar.gz: 12533be2ad6de518f39e29790aa6caad27a6eebc3ee5b7e00201f13beffe8f04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd3c1084b77af29adf4e42ee89936bc53338e680a55cd9300a0ca734f0aae97d964b59930b19d78c357bf8817a668cafe6f661f563e3875002a0094c09ce20a8
|
7
|
+
data.tar.gz: 3090d4acffb28baf78d824a6ddefe5f222b858b8a1d72e1c76d5c03c15992d167a8b28f35c6e6daf6a333dbdf4f0c8d3142caa0e6dba7bfef9ea4e1790b54596
|
@@ -42,83 +42,131 @@ module Jekyll
|
|
42
42
|
@@sizes[input] = sizes.split(',', 2).map!(&:to_i)
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
# Throw error if it is not an absolute path
|
46
|
+
def check_path(input, filter_name)
|
47
47
|
if not input.is_a? String || input.length == 0 || input.chr != '/'
|
48
|
-
throw "
|
48
|
+
throw "#{filter_name}: path must be an absolute path"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Return true if the file exists and is an image mime type
|
53
|
+
def is_image?(src)
|
54
|
+
cmd = "identify -ping #{src.shellescape} 2>&1"
|
55
|
+
output = `#{cmd}`
|
56
|
+
|
57
|
+
if not $?.success?
|
58
|
+
if output.include?("identify: improper image header")
|
59
|
+
throw "file is not an image: '#{src}'"
|
60
|
+
else
|
61
|
+
throw "width/height: failed to execute 'identity', is ImageMagick installed?"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
return true
|
66
|
+
end
|
67
|
+
|
68
|
+
# Convert an image from src to dst with the given width
|
69
|
+
def convert(src, src_extname, dst, width)
|
70
|
+
site = @context.registers[:site]
|
71
|
+
quality = site.config['responsive']['quality'] || 80
|
72
|
+
verbose = site.config['responsive']['verbose'] || false
|
73
|
+
|
74
|
+
if File.exist?(dst) and File.mtime(src) < File.mtime(dst)
|
75
|
+
return
|
49
76
|
end
|
77
|
+
|
78
|
+
FileUtils.mkdir_p(File.dirname(dst))
|
79
|
+
cmd = "convert #{src_extname == '.apng' ? 'apng:' : ''}#{src.shellescape} -strip -quality #{quality} -resize #{width} #{dst.shellescape}"
|
80
|
+
|
81
|
+
if verbose
|
82
|
+
print("#{cmd}\n")
|
83
|
+
end
|
84
|
+
|
85
|
+
if not system(cmd)
|
86
|
+
throw "srcset: failed to execute 'convert', is ImageMagick installed?"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def srcset(input)
|
91
|
+
check_path(input, "srcset")
|
92
|
+
site = @context.registers[:site]
|
50
93
|
dirname = File.dirname(input)
|
51
94
|
basename = File.basename(input, '.*')
|
52
95
|
extname = File.extname(input)
|
96
|
+
new_extname = site.config['responsive']['format'] ? ".#{site.config['responsive']['format']}" : extname
|
53
97
|
src = ".#{dirname}/#{basename}#{extname}"
|
54
|
-
srcwidth = width(input)
|
98
|
+
srcwidth = width(input, "srcset")
|
55
99
|
srcset = ["#{input} #{srcwidth}w"]
|
56
100
|
|
57
|
-
if File.exist?(src)
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
# as default, use breakpoints of Bootstrap 5
|
63
|
-
widths = [576,768,992,1200,1400]
|
64
|
-
end
|
65
|
-
if site.config['responsive']['quality']
|
66
|
-
quality = site.config['responsive']['quality']
|
67
|
-
else
|
68
|
-
quality = 80
|
69
|
-
end
|
70
|
-
if site.config['responsive']['verbose']
|
71
|
-
verbose = site.config['responsive']['verbose']
|
72
|
-
else
|
73
|
-
verbose = false
|
74
|
-
end
|
101
|
+
if not File.exist?(src) or not is_image?(src)
|
102
|
+
throw "srcset: file does not exist or is not an image: '#{src}'"
|
103
|
+
elsif File.extname(src) != '.svg'
|
104
|
+
# as default, use breakpoints of Bootstrap 5
|
105
|
+
widths = site.config['responsive']['widths'] || [576, 768, 992, 1200, 1400]
|
75
106
|
|
76
107
|
widths.map do |width|
|
77
|
-
if srcwidth > width
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
cmd = "convert #{src.shellescape} -strip -quality #{quality} -resize #{width} #{dst.shellescape}"
|
88
|
-
end
|
89
|
-
if verbose
|
90
|
-
print("#{cmd}\n")
|
91
|
-
end
|
92
|
-
if not system(cmd)
|
93
|
-
throw "srcset: failed to execute 'convert', is ImageMagick installed?"
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
srcset.push("#{dirname}/#{file} #{width}w")
|
108
|
+
if not srcwidth > width
|
109
|
+
next # image is not large enough to generate a smaller version
|
110
|
+
end
|
111
|
+
|
112
|
+
file = "#{basename}-#{width}w#{new_extname}"
|
113
|
+
dst = "_responsive#{dirname}/#{file}"
|
114
|
+
srcset.push("#{dirname}/#{file} #{width}w")
|
115
|
+
|
116
|
+
if site.static_files.find{|file| file.path == dst}
|
117
|
+
next # image is already generated
|
98
118
|
end
|
119
|
+
|
120
|
+
site.static_files << StaticFile.new(site, "_responsive", dirname, file)
|
121
|
+
convert(src, extname, dst, width)
|
99
122
|
end
|
100
123
|
end
|
124
|
+
|
101
125
|
return srcset.join(', ')
|
102
126
|
end
|
103
127
|
|
104
|
-
def width(input)
|
105
|
-
|
106
|
-
|
107
|
-
|
128
|
+
def width(input, from = "width")
|
129
|
+
check_size(input, from)
|
130
|
+
return @@sizes[input][0]
|
131
|
+
end
|
132
|
+
|
133
|
+
def height(input, from = "width")
|
134
|
+
check_size(input, from)
|
135
|
+
return @@sizes[input][1]
|
136
|
+
end
|
137
|
+
|
138
|
+
def check_size(input, from)
|
139
|
+
check_path(input, from)
|
108
140
|
if not @@sizes[input]
|
109
141
|
identify(input)
|
110
142
|
end
|
111
|
-
return @@sizes[input][0]
|
112
143
|
end
|
113
144
|
|
114
|
-
def
|
115
|
-
|
116
|
-
|
145
|
+
def size(input, width)
|
146
|
+
check_path(input, "size")
|
147
|
+
site = @context.registers[:site]
|
148
|
+
dirname = File.dirname(input)
|
149
|
+
basename = File.basename(input, '.*')
|
150
|
+
extname = File.extname(input)
|
151
|
+
new_extname = site.config['responsive']['format'] ? ".#{site.config['responsive']['format']}" : extname
|
152
|
+
src = ".#{dirname}/#{basename}#{extname}"
|
153
|
+
|
154
|
+
if not File.exist?(src) or not is_image?(src)
|
155
|
+
throw "srcset: file does not exist or is not an image: '#{src}'"
|
117
156
|
end
|
118
|
-
|
119
|
-
|
157
|
+
|
158
|
+
file = "#{basename}-#{width}w#{new_extname}"
|
159
|
+
dst = "_responsive#{dirname}/#{file}"
|
160
|
+
full_path = "#{dirname}/#{file}"
|
161
|
+
|
162
|
+
if site.static_files.find{|file| file.path == dst}
|
163
|
+
return full_path # image is already generated
|
120
164
|
end
|
121
|
-
|
165
|
+
|
166
|
+
site.static_files << StaticFile.new(site, "_responsive", dirname, file)
|
167
|
+
convert(src, extname, dst, width)
|
168
|
+
|
169
|
+
return full_path
|
122
170
|
end
|
123
171
|
end
|
124
172
|
end
|
metadata
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-responsive-magick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lawrence Murray
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A Jekyll plugin for responsive images. Adds filters for setting the srcset,
|
14
14
|
width and height attributes of HTML img elements, while automatically generating
|
15
15
|
image variants of configured sizes using the ImageMagick command-line tools. Resized
|
16
16
|
images are cached to minimize build times, regenerated only when the original source
|
17
|
-
image changes. Supported image file formats
|
18
|
-
and
|
17
|
+
image changes. Supported image file formats include JPEG, PNG, GIF (including animated),
|
18
|
+
APNG and WebP.
|
19
19
|
email: lawrence@indii.org
|
20
20
|
executables: []
|
21
21
|
extensions: []
|
@@ -30,7 +30,7 @@ metadata:
|
|
30
30
|
bug_tracker_uri: https://github.com/lawmurray/jekyll-responsive-magick/issues
|
31
31
|
homepage_uri: https://indii.org/software/jekyll-responsive-magick
|
32
32
|
source_code_uri: https://github.com/lawmurray/jekyll-responsive-magick
|
33
|
-
post_install_message:
|
33
|
+
post_install_message:
|
34
34
|
rdoc_options: []
|
35
35
|
require_paths:
|
36
36
|
- lib
|
@@ -45,9 +45,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
47
|
requirements: []
|
48
|
-
|
49
|
-
|
50
|
-
signing_key:
|
48
|
+
rubygems_version: 3.3.15
|
49
|
+
signing_key:
|
51
50
|
specification_version: 4
|
52
51
|
summary: A Jekyll plugin for responsive images using ImageMagick. Works with Jekyll
|
53
52
|
4.
|