jekyll-images 0.2.2 → 0.2.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/lib/jekyll-images.rb +1 -0
- data/lib/jekyll/filters/thumbnail.rb +25 -13
- data/lib/jekyll/images/image.rb +29 -0
- data/lib/jekyll/images/thumbnail.rb +38 -23
- metadata +32 -72
- data/.gitignore +0 -8
- data/.travis.yml +0 -7
- data/Gemfile +0 -5
- data/Rakefile +0 -10
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/jekyll-images.gemspec +0 -40
- data/lib/jekyll/images/version.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8aaeed177d571388aaee458474e013b9c99f0965bc48bd1a22d4041a1dcef38d
|
4
|
+
data.tar.gz: 475e6843df583c9dc11c5742fa5cf9afc12ca22f171ba99fc2b7d04d069a7847
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ce335efa57aa6d2f82f0fef851ae192a748c9e2245d87187da6f598ec0add082be44a9fb5594d5f8f4675b3505f9f562aa606d52ea1cb397e3af8fd85e6953c
|
7
|
+
data.tar.gz: 717f5b7681bafb34f86bff82845b776281640d6c79b12d83c1d43f9b85ff5fbdeaf5c80f182c6c7221afa8f3154775d105fef21b34c2eb766c80710c200ccc39
|
data/README.md
CHANGED
@@ -53,10 +53,12 @@ In your templates, you can use the `thumbnail` filter:
|
|
53
53
|
|
54
54
|
Options for this filter are in the following order:
|
55
55
|
|
56
|
-
* `width
|
56
|
+
* `width`, the desired width for the image, if `nil`, `height` is
|
57
|
+
required.
|
57
58
|
|
58
59
|
* `height`, if provided, the thumbnail will crop to this size. If not,
|
59
|
-
the image is scaled down proportionally to the width.
|
60
|
+
the image is scaled down proportionally to the width. It becomes
|
61
|
+
required if the width is `nil`.
|
60
62
|
|
61
63
|
* `crop` the smart cropping algorithm. One of `none`, `centre`,
|
62
64
|
`entropy` or `attention` (default). See
|
@@ -67,7 +69,7 @@ Options for this filter are in the following order:
|
|
67
69
|
orientation metadata, this controls if it's automatically rotated.
|
68
70
|
|
69
71
|
If you want to pass `crop` and `auto_rotate` but not `height`, just set
|
70
|
-
`height` to `
|
72
|
+
`height` to `nil`.
|
71
73
|
|
72
74
|
## TODO
|
73
75
|
|
data/lib/jekyll-images.rb
CHANGED
@@ -4,22 +4,34 @@ module Jekyll
|
|
4
4
|
module Filters
|
5
5
|
# Liquid filter for use in templates
|
6
6
|
module Thumbnail
|
7
|
+
@@cached_images = {}
|
8
|
+
|
7
9
|
# Generates a thumbnail and returns its alternate destination
|
8
|
-
def thumbnail(input, width, height = nil, crop =
|
10
|
+
def thumbnail(input, width = nil, height = nil, crop = nil, auto_rotate = nil)
|
9
11
|
return unless input
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
13
|
+
image = cached_image input
|
14
|
+
thumb = image.thumbnail(width: width,
|
15
|
+
height: height,
|
16
|
+
crop: crop,
|
17
|
+
auto_rotate: auto_rotate)
|
18
|
+
|
19
|
+
thumb.write && thumb.optimize
|
20
|
+
|
21
|
+
thumb.dest
|
22
|
+
rescue Vips::Error => e
|
23
|
+
Jekyll.logger.warn "Failed to process #{input}: #{e.message}"
|
24
|
+
input
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def cached_image?(input)
|
30
|
+
@@cached_images.key? input
|
31
|
+
end
|
32
|
+
|
33
|
+
def cached_image(input)
|
34
|
+
@@cached_images[input] ||= Jekyll::Images::Image.new(@context.registers[:site], input)
|
23
35
|
end
|
24
36
|
end
|
25
37
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'vips'
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
module Images
|
7
|
+
class Image
|
8
|
+
attr_reader :site, :filename
|
9
|
+
|
10
|
+
def initialize(site, filename)
|
11
|
+
unless File.exist? filename
|
12
|
+
raise ArgumentError, "File not found: #{filename}"
|
13
|
+
end
|
14
|
+
|
15
|
+
@cached_thumbnails = {}
|
16
|
+
@site = site
|
17
|
+
@filename = filename
|
18
|
+
end
|
19
|
+
|
20
|
+
def image
|
21
|
+
@image ||= Vips::Image.new_from_file filename, access: :sequential
|
22
|
+
end
|
23
|
+
|
24
|
+
def thumbnail(**args)
|
25
|
+
@cached_thumbnails[args.hash.to_s] ||= Thumbnail.new site: site, filename: filename, image: image, **args
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -4,44 +4,54 @@ require 'vips'
|
|
4
4
|
|
5
5
|
module Jekyll
|
6
6
|
module Images
|
7
|
-
# Use LibVIPS to generate images in different sizes
|
8
|
-
#
|
9
|
-
# We're assuming every image is going to be thumbnailed
|
10
7
|
class Thumbnail
|
11
|
-
attr_reader :site, :image, :
|
8
|
+
attr_reader :site, :filename, :image, :width, :height, :crop, :auto_rotate
|
12
9
|
|
13
|
-
def initialize(site
|
14
|
-
|
15
|
-
raise ArgumentError, "
|
10
|
+
def initialize(site:, filename:, image:, **args)
|
11
|
+
if args.slice(:width, :height).values.none?
|
12
|
+
raise ArgumentError, "#{filename} thumbnail needs width or height"
|
16
13
|
end
|
17
|
-
raise ArgumentError, 'Missing width' unless args[:width]
|
18
14
|
|
19
15
|
@site = site
|
20
16
|
@filename = filename
|
21
|
-
@
|
22
|
-
@
|
23
|
-
@
|
24
|
-
@
|
25
|
-
|
26
|
-
|
27
|
-
|
17
|
+
@image = image
|
18
|
+
@width = args[:width] || proportional_width(args[:height])
|
19
|
+
@height = args[:height] || proportional_height(args[:width])
|
20
|
+
@crop = args[:crop]&.to_sym || :attention
|
21
|
+
@auto_rotate = args[:auto_rotate].nil? ? true : args[:auto_rotate]
|
22
|
+
end
|
23
|
+
|
24
|
+
def thumbnail
|
25
|
+
@thumbnail ||= Vips::Image.thumbnail filename,
|
26
|
+
width,
|
27
|
+
height: height,
|
28
|
+
auto_rotate: auto_rotate,
|
29
|
+
crop: crop
|
28
30
|
end
|
29
31
|
|
30
32
|
# Finds a height that's proportional to the width
|
31
|
-
def proportional_height
|
32
|
-
@
|
33
|
+
def proportional_height(width)
|
34
|
+
@proportional_height ||= (image.height * (width / image.width.to_f)).round
|
35
|
+
end
|
36
|
+
|
37
|
+
# Find a width that's proportional to height
|
38
|
+
def proportional_width(height)
|
39
|
+
@proportional_width ||= (image.width * (height / image.height.to_f)).round
|
33
40
|
end
|
34
41
|
|
35
42
|
# Generates a destination from filename only if we're downsizing
|
36
43
|
def dest
|
37
|
-
@dest ||= if
|
44
|
+
@dest ||= if thumbnail?
|
38
45
|
filename.gsub(/#{extname}\z/, "_#{width}x#{height}#{extname}")
|
39
46
|
else
|
40
|
-
|
41
|
-
filename
|
47
|
+
filename.gsub(/#{extname}\z/, "_optimized#{extname}")
|
42
48
|
end
|
43
49
|
end
|
44
50
|
|
51
|
+
def thumbnail?
|
52
|
+
image.width > width
|
53
|
+
end
|
54
|
+
|
45
55
|
def extname
|
46
56
|
@extname ||= File.extname filename
|
47
57
|
end
|
@@ -56,8 +66,13 @@ module Jekyll
|
|
56
66
|
def write
|
57
67
|
return unless write?
|
58
68
|
|
59
|
-
|
60
|
-
|
69
|
+
if thumbnail?
|
70
|
+
Jekyll.logger.info "Thumbnailing #{filename} => #{dest}"
|
71
|
+
thumbnail.write_to_file(dest)
|
72
|
+
else
|
73
|
+
Jekyll.logger.info "Copying #{filename} => #{dest}"
|
74
|
+
FileUtils.cp(filename, dest)
|
75
|
+
end
|
61
76
|
|
62
77
|
# Add it to the static files so Jekyll copies them. Once they
|
63
78
|
# are written they're copied when the site is loaded.
|
@@ -77,7 +92,7 @@ module Jekyll
|
|
77
92
|
|
78
93
|
pct = ((after.to_f / before) * -100 + 100).round(2)
|
79
94
|
|
80
|
-
Jekyll.logger.info "Reduced #{
|
95
|
+
Jekyll.logger.info "Reduced #{dest} from #{before} to #{after} bytes (%#{pct})"
|
81
96
|
end
|
82
97
|
end
|
83
98
|
end
|
metadata
CHANGED
@@ -1,139 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-images
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- f
|
8
|
-
autorequire:
|
9
|
-
bindir:
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: jekyll
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: ruby-
|
28
|
+
name: ruby-vips
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: bundler
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '2.0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '2.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: minitest
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '5.0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '5.0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rake
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '10.0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '10.0'
|
40
|
+
version: '2'
|
83
41
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
42
|
+
name: ruby-filemagic
|
85
43
|
requirement: !ruby/object:Gem::Requirement
|
86
44
|
requirements:
|
87
45
|
- - "~>"
|
88
46
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0.
|
90
|
-
type: :
|
47
|
+
version: '0.7'
|
48
|
+
type: :runtime
|
91
49
|
prerelease: false
|
92
50
|
version_requirements: !ruby/object:Gem::Requirement
|
93
51
|
requirements:
|
94
52
|
- - "~>"
|
95
53
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0.
|
54
|
+
version: '0.7'
|
97
55
|
description: Optimizes images for Jekyll
|
98
56
|
email:
|
99
57
|
- f@sutty.nl
|
100
58
|
executables: []
|
101
59
|
extensions: []
|
102
|
-
extra_rdoc_files:
|
60
|
+
extra_rdoc_files:
|
61
|
+
- README.md
|
62
|
+
- LICENSE
|
103
63
|
files:
|
104
|
-
- ".gitignore"
|
105
|
-
- ".travis.yml"
|
106
|
-
- Gemfile
|
107
64
|
- LICENSE
|
108
65
|
- README.md
|
109
|
-
- Rakefile
|
110
|
-
- bin/console
|
111
|
-
- bin/setup
|
112
|
-
- jekyll-images.gemspec
|
113
66
|
- lib/jekyll-images.rb
|
114
67
|
- lib/jekyll/filters/thumbnail.rb
|
68
|
+
- lib/jekyll/images/image.rb
|
115
69
|
- lib/jekyll/images/jpeg_optim.rb
|
116
70
|
- lib/jekyll/images/oxipng.rb
|
117
71
|
- lib/jekyll/images/runner.rb
|
118
72
|
- lib/jekyll/images/thumbnail.rb
|
119
|
-
- lib/jekyll/images/version.rb
|
120
73
|
homepage: https://0xacab.org/sutty/jekyll/jekyll-images
|
121
74
|
licenses:
|
122
75
|
- GPL-3.0
|
123
76
|
metadata:
|
124
|
-
|
77
|
+
bug_tracker_uri: https://0xacab.org/sutty/jekyll/jekyll-images/issues
|
125
78
|
homepage_uri: https://0xacab.org/sutty/jekyll/jekyll-images
|
126
79
|
source_code_uri: https://0xacab.org/sutty/jekyll/jekyll-images
|
127
|
-
|
128
|
-
post_install_message:
|
129
|
-
rdoc_options:
|
80
|
+
documentation_uri: https://rubydoc.info/gems/jekyll-images
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options:
|
83
|
+
- "--title"
|
84
|
+
- jekyll-images - Optimizes images for Jekyll
|
85
|
+
- "--main"
|
86
|
+
- README.md
|
87
|
+
- "--line-numbers"
|
88
|
+
- "--inline-source"
|
89
|
+
- "--quiet"
|
130
90
|
require_paths:
|
131
91
|
- lib
|
132
92
|
required_ruby_version: !ruby/object:Gem::Requirement
|
133
93
|
requirements:
|
134
|
-
- - "
|
94
|
+
- - "~>"
|
135
95
|
- !ruby/object:Gem::Version
|
136
|
-
version: '
|
96
|
+
version: '2'
|
137
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
98
|
requirements:
|
139
99
|
- - ">="
|
@@ -141,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
101
|
version: '0'
|
142
102
|
requirements: []
|
143
103
|
rubygems_version: 3.0.3
|
144
|
-
signing_key:
|
104
|
+
signing_key:
|
145
105
|
specification_version: 4
|
146
106
|
summary: Optimizes images for Jekyll
|
147
107
|
test_files: []
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "jekyll/image/optimization"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|
data/bin/setup
DELETED
data/jekyll-images.gemspec
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
lib = File.expand_path('lib', __dir__)
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require 'jekyll/images/version'
|
6
|
-
|
7
|
-
Gem::Specification.new do |spec|
|
8
|
-
spec.name = 'jekyll-images'
|
9
|
-
spec.version = Jekyll::Images::VERSION
|
10
|
-
spec.authors = ['f']
|
11
|
-
spec.email = ['f@sutty.nl']
|
12
|
-
|
13
|
-
spec.summary = 'Optimizes images for Jekyll'
|
14
|
-
spec.description = 'Optimizes images for Jekyll'
|
15
|
-
spec.homepage = 'https://0xacab.org/sutty/jekyll/jekyll-images'
|
16
|
-
spec.license = 'GPL-3.0'
|
17
|
-
|
18
|
-
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
19
|
-
|
20
|
-
spec.metadata['homepage_uri'] = spec.homepage
|
21
|
-
spec.metadata['source_code_uri'] = spec.homepage
|
22
|
-
spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/CHANGELOG.md"
|
23
|
-
|
24
|
-
# Specify which files should be added to the gem when it is released.
|
25
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
26
|
-
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
27
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
|
-
end
|
29
|
-
spec.bindir = 'exe'
|
30
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
-
spec.require_paths = ['lib']
|
32
|
-
|
33
|
-
spec.add_dependency 'ruby-vips', '~> 2'
|
34
|
-
spec.add_dependency 'ruby-filemagic', '~> 0.7'
|
35
|
-
|
36
|
-
spec.add_development_dependency 'bundler', '~> 2.0'
|
37
|
-
spec.add_development_dependency 'minitest', '~> 5.0'
|
38
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
39
|
-
spec.add_development_dependency 'rubocop', '~> 0.74'
|
40
|
-
end
|