jekyll-images 0.2.3 → 0.2.7
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 +31 -0
- data/lib/jekyll/images/thumbnail.rb +36 -32
- 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: 9343975c53eefd5a9e88ed8ef249455a5fc82ca6ae5ba5b36ce46f369ee0d24b
|
4
|
+
data.tar.gz: 2ab5924b0216ff9354bb404316f43b09448431d04fcfe9ae5233ca4da347f8a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52d5e60cc1edfb8e5a72dcbdbfaf062d51846fe0a281103ece714fc5251ee75d9c3f9c19ee3ac7e137c147f8a9a56b3c79fde6df28488f353923cc0b623f96a1
|
7
|
+
data.tar.gz: fccc5454c030535ace052d299c4f34b419d6d698aa3ff24fd3447adc52414118bb144204bdccf7ce04dd89f00b13be1200f8d3e823e20b9579ac9b1cef8d93ef
|
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,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'vips'
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
module Images
|
7
|
+
class Image
|
8
|
+
attr_reader :site, :filename, :height, :width
|
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
|
+
|
19
|
+
# We only need the image to get height and width
|
20
|
+
image = Vips::Image.new_from_file filename, access: :sequential
|
21
|
+
|
22
|
+
@height = image.height
|
23
|
+
@width = image.width
|
24
|
+
end
|
25
|
+
|
26
|
+
def thumbnail(**args)
|
27
|
+
@cached_thumbnails[args.hash.to_s] ||= Thumbnail.new site: site, filename: filename, image: self, **args
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -4,57 +4,56 @@ 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, :filename, :width, :height, :crop, :auto_rotate
|
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
|
-
def image
|
28
|
-
@image ||= Vips::Image.new_from_file filename,
|
29
|
-
access: :sequential
|
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]
|
30
22
|
end
|
31
23
|
|
24
|
+
# XXX: We don't memoize because we don't need the thumbnail in
|
25
|
+
# memory after it has been written.
|
32
26
|
def thumbnail
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
27
|
+
Vips::Image.thumbnail filename,
|
28
|
+
width,
|
29
|
+
height: height,
|
30
|
+
auto_rotate: auto_rotate,
|
31
|
+
crop: crop
|
37
32
|
end
|
38
33
|
|
39
|
-
|
40
|
-
|
34
|
+
# Finds a height that's proportional to the width
|
35
|
+
def proportional_height(width)
|
36
|
+
@proportional_height ||= (image.height * (width / image.width.to_f)).round
|
41
37
|
end
|
42
38
|
|
43
|
-
#
|
44
|
-
def
|
45
|
-
@
|
39
|
+
# Find a width that's proportional to height
|
40
|
+
def proportional_width(height)
|
41
|
+
@proportional_width ||= (image.width * (height / image.height.to_f)).round
|
46
42
|
end
|
47
43
|
|
48
44
|
# Generates a destination from filename only if we're downsizing
|
49
45
|
def dest
|
50
|
-
@dest ||= if
|
46
|
+
@dest ||= if thumbnail?
|
51
47
|
filename.gsub(/#{extname}\z/, "_#{width}x#{height}#{extname}")
|
52
48
|
else
|
53
|
-
|
54
|
-
filename
|
49
|
+
filename.gsub(/#{extname}\z/, "_optimized#{extname}")
|
55
50
|
end
|
56
51
|
end
|
57
52
|
|
53
|
+
def thumbnail?
|
54
|
+
image.width > width
|
55
|
+
end
|
56
|
+
|
58
57
|
def extname
|
59
58
|
@extname ||= File.extname filename
|
60
59
|
end
|
@@ -69,8 +68,13 @@ module Jekyll
|
|
69
68
|
def write
|
70
69
|
return unless write?
|
71
70
|
|
72
|
-
|
73
|
-
|
71
|
+
if thumbnail?
|
72
|
+
Jekyll.logger.info "Thumbnailing #{filename} => #{dest}"
|
73
|
+
thumbnail.write_to_file(dest)
|
74
|
+
else
|
75
|
+
Jekyll.logger.info "Copying #{filename} => #{dest}"
|
76
|
+
FileUtils.cp(filename, dest)
|
77
|
+
end
|
74
78
|
|
75
79
|
# Add it to the static files so Jekyll copies them. Once they
|
76
80
|
# are written they're copied when the site is loaded.
|
@@ -90,7 +94,7 @@ module Jekyll
|
|
90
94
|
|
91
95
|
pct = ((after.to_f / before) * -100 + 100).round(2)
|
92
96
|
|
93
|
-
Jekyll.logger.info "Reduced #{
|
97
|
+
Jekyll.logger.info "Reduced #{dest} from #{before} to #{after} bytes (%#{pct})"
|
94
98
|
end
|
95
99
|
end
|
96
100
|
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.7
|
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-28 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
|