jekyll-images 0.3.2 → 0.4.0rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +35 -0
- data/lib/jekyll/filters/dzsave.rb +33 -0
- data/lib/jekyll/filters/thumbnail.rb +3 -1
- data/lib/jekyll/images/image.rb +4 -0
- data/lib/jekyll/images/jpeg_optim.rb +1 -1
- data/lib/jekyll/images/oxipng.rb +1 -1
- data/lib/jekyll/images/runner.rb +5 -4
- data/lib/jekyll/images/thumbnail.rb +5 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8fb884679503e21d7cec255f22cd496b338ee6783b763249b94df7c9f719ec2
|
4
|
+
data.tar.gz: d2103b9d5ac82b643c5099e5a7f2a9ddb813951c81f429a0dd41822a4450e865
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 106b016d8420dcd171cc7676715b3bf3ba6f272e0cd678f369b3b9f264697dd4734ba2d62b30ff532023553c0467abf37762c3f4945bb32b3c2f05a400ae8d81
|
7
|
+
data.tar.gz: e895b2a0c9f623050ab911dc829ce22696ee72a0477944c260cc1ff0a7396a2cbcb24b06c9c16ee0a737c5513c9fb6d577510c1c86d66b5dbe07809f13f41b1c
|
data/README.md
CHANGED
@@ -31,8 +31,43 @@ Or install it yourself as:
|
|
31
31
|
|
32
32
|
$ gem install jekyll-images
|
33
33
|
|
34
|
+
For image optimization, install packages containing `jpegoptim` and
|
35
|
+
`oxipng`.
|
36
|
+
|
37
|
+
## Configuration
|
38
|
+
|
39
|
+
Everything is handled automatically. If image optimizers are found,
|
40
|
+
thumbnails are automatically optimized.
|
41
|
+
|
42
|
+
### Interlaced / Progressive images
|
43
|
+
|
44
|
+
Interlaced images makes them appear to load faster, because the image
|
45
|
+
loads dimensions and gains quality as it downloads. According to
|
46
|
+
Cloudflare, at 50% download the image looks almost like the final
|
47
|
+
image[^0], even though interlaced images tend to use more disk space.
|
48
|
+
|
49
|
+
To enable interlacing, add to `_config.yml`:
|
50
|
+
|
51
|
+
```yaml
|
52
|
+
images:
|
53
|
+
interlaced: true
|
54
|
+
```
|
55
|
+
|
56
|
+
**Note:** Interlacing sometimes won't make the images smaller.
|
57
|
+
|
58
|
+
[^0]:
|
59
|
+
<https://blog.cloudflare.com/parallel-streaming-of-progressive-images/>
|
60
|
+
|
34
61
|
## Usage
|
35
62
|
|
63
|
+
### Only builds on production
|
64
|
+
|
65
|
+
To perform actual thumbnailing, run `jekyll build` in production mode:
|
66
|
+
|
67
|
+
```bash
|
68
|
+
JEKYLL_ENV=production bundle exec jekyll build
|
69
|
+
```
|
70
|
+
|
36
71
|
### Liquid templates
|
37
72
|
|
38
73
|
In your templates, you can use the `thumbnail` filter:
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Filters
|
5
|
+
# Liquid filter for use in templates
|
6
|
+
module Dzsave
|
7
|
+
# Generates an image pyramid
|
8
|
+
#
|
9
|
+
# @see {https://www.libvips.org/API/current/Making-image-pyramids.md.html}
|
10
|
+
def dzsave(input, layout = 'google', tile_size = 256)
|
11
|
+
return input unless input
|
12
|
+
|
13
|
+
path = @context.registers[:site].in_source_dir input
|
14
|
+
|
15
|
+
unless ::File.exist? path
|
16
|
+
Jekyll.logger.warn "File doesn't exist #{input}"
|
17
|
+
return input
|
18
|
+
end
|
19
|
+
|
20
|
+
dir = ::File.dirname(input)
|
21
|
+
image = Vips::Image.new_from_file path, access: :sequential
|
22
|
+
image.dzsave(dir, layout: layout, tile_size: tile_size)
|
23
|
+
|
24
|
+
"#{dir}/{z}/{y}/{x}.#{::File.extname input}"
|
25
|
+
rescue Vips::Error => e
|
26
|
+
Jekyll.logger.warn "Failed to process #{input}: #{e.message}"
|
27
|
+
input
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Liquid::Template.register_filter(Jekyll::Filters::Dzsave)
|
@@ -6,7 +6,9 @@ module Jekyll
|
|
6
6
|
module Thumbnail
|
7
7
|
# Generates a thumbnail and returns its alternate destination
|
8
8
|
def thumbnail(input, width = nil, height = nil, crop = nil, auto_rotate = nil)
|
9
|
-
return unless input
|
9
|
+
return input unless input
|
10
|
+
return input unless Jekyll.env == 'production'
|
11
|
+
|
10
12
|
path = @context.registers[:site].in_source_dir input
|
11
13
|
|
12
14
|
unless ::File.exist? path
|
data/lib/jekyll/images/image.rb
CHANGED
data/lib/jekyll/images/oxipng.rb
CHANGED
data/lib/jekyll/images/runner.rb
CHANGED
@@ -7,7 +7,7 @@ module Jekyll
|
|
7
7
|
module Images
|
8
8
|
# Runner for optimizations
|
9
9
|
class Runner
|
10
|
-
attr_reader :binary, :bytes_after, :bytes_before, :file
|
10
|
+
attr_reader :binary, :bytes_after, :bytes_before, :file, :interlaced
|
11
11
|
|
12
12
|
class << self
|
13
13
|
# XXX: This only allows one optimization per file type, we could
|
@@ -28,15 +28,16 @@ module Jekyll
|
|
28
28
|
@@mime.file(file, true)
|
29
29
|
end
|
30
30
|
|
31
|
-
def run(file)
|
31
|
+
def run(file, interlaced = false)
|
32
32
|
type = mime(file)
|
33
|
-
runners[type].new(file).run if runners[type]
|
33
|
+
runners[type].new(file, interlaced).run if runners[type]
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
def initialize(file)
|
37
|
+
def initialize(file, interlaced = false)
|
38
38
|
@file = file
|
39
39
|
@bytes_before = bytes_after
|
40
|
+
@interlaced = interlaced
|
40
41
|
end
|
41
42
|
|
42
43
|
def bytes_after
|
@@ -90,7 +90,7 @@ module Jekyll
|
|
90
90
|
|
91
91
|
# Run optimizations
|
92
92
|
def optimize
|
93
|
-
before, after = Runner.run(dest)
|
93
|
+
before, after = Runner.run(dest, interlaced?)
|
94
94
|
|
95
95
|
return unless before
|
96
96
|
|
@@ -106,6 +106,10 @@ module Jekyll
|
|
106
106
|
def static_file
|
107
107
|
@static_file ||= Jekyll::StaticFile.new(site, site.source, File.dirname(relative_path), File.basename(relative_path))
|
108
108
|
end
|
109
|
+
|
110
|
+
def interlaced?
|
111
|
+
site.config.dig('images', 'interlaced')
|
112
|
+
end
|
109
113
|
end
|
110
114
|
end
|
111
115
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-images
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- f
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- LICENSE
|
65
65
|
- README.md
|
66
66
|
- lib/jekyll-images.rb
|
67
|
+
- lib/jekyll/filters/dzsave.rb
|
67
68
|
- lib/jekyll/filters/height.rb
|
68
69
|
- lib/jekyll/filters/thumbnail.rb
|
69
70
|
- lib/jekyll/filters/width.rb
|
@@ -99,9 +100,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
100
|
version: '2'
|
100
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
102
|
requirements:
|
102
|
-
- - "
|
103
|
+
- - ">"
|
103
104
|
- !ruby/object:Gem::Version
|
104
|
-
version:
|
105
|
+
version: 1.3.1
|
105
106
|
requirements: []
|
106
107
|
rubygems_version: 3.1.6
|
107
108
|
signing_key:
|