jekyll_picture_tag 1.12.0 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 57fe7741c94cf1511eb8824dec643e9acb953b3251b2714b030e662742d62680
4
- data.tar.gz: fcfae3154dcfe87509bc4759171ab6f2a27636ab75d6ec20d24b335f8535dc8c
3
+ metadata.gz: 46fd8634e4d9eff8493b340560d84e8a398eb77db81a511529f0b670f111de7c
4
+ data.tar.gz: 103f00baec1839e018094b5c3d3522ecff13849e3bda46353ddde9e70e2040fb
5
5
  SHA512:
6
- metadata.gz: af9a456fb275f80eedff3c26a1579c3ce95b2385fd66f1a7e203947de2e16deea596f2e6a1334f5cb475e4d61c26803569bd522a84356a574b826cc071961fa3
7
- data.tar.gz: a6fb8984f4fe3b02564a60038d77136d15c5fd1625a1e8b5f654b656494eb8e9b1f7f497436145253e8f241d5cb902243df37ff38511a05b742c5c2de1c5730d
6
+ metadata.gz: 14afd21d6a1cd36bac48b20e79047e1df845b458e763d0eb590125fa45dd2eef431cc27836f22073878d807dc5118787f40fe8b2ffc15579bd6edf4c70f0411b
7
+ data.tar.gz: bd9131318cd312b340ff337db88127c9b8b14f78c2bfc64ec04dd6f9d27db87a08d36a59bf5aa550f51ede5c2a6b9cdda8554c60f2cecc64db5e914a1f28a84f
@@ -1,6 +1,81 @@
1
+ # Disabled
1
2
  Style/FrozenStringLiteralComment:
2
3
  Enabled: false
3
4
 
4
- AllCops:
5
- NewCops: enable
6
-
5
+ Style/StringConcatenation:
6
+ Enabled: false
7
+
8
+ # New cops, enabled. We aren't using the 'NewCops' setting because then rubocop
9
+ # updates can break our CI.
10
+ Layout/EmptyLinesAroundAttributeAccessor:
11
+ Enabled: true
12
+ Layout/SpaceAroundMethodCallOperator:
13
+ Enabled: true
14
+ Lint/BinaryOperatorWithIdenticalOperands:
15
+ Enabled: true
16
+ Lint/DeprecatedOpenSSLConstant:
17
+ Enabled: true
18
+ Lint/DuplicateElsifCondition:
19
+ Enabled: true
20
+ Lint/DuplicateRescueException:
21
+ Enabled: true
22
+ Lint/EmptyConditionalBody:
23
+ Enabled: true
24
+ Lint/FloatComparison:
25
+ Enabled: true
26
+ Lint/MissingSuper:
27
+ Enabled: true
28
+ Lint/MixedRegexpCaptureTypes:
29
+ Enabled: true
30
+ Lint/OutOfRangeRegexpRef:
31
+ Enabled: true
32
+ Lint/RaiseException:
33
+ Enabled: true
34
+ Lint/SelfAssignment:
35
+ Enabled: true
36
+ Lint/StructNewOverride:
37
+ Enabled: true
38
+ Lint/TopLevelReturnWithArgument:
39
+ Enabled: true
40
+ Lint/UnreachableLoop:
41
+ Enabled: true
42
+ Style/AccessorGrouping:
43
+ Enabled: true
44
+ Style/ArrayCoercion:
45
+ Enabled: true
46
+ Style/BisectedAttrAccessor:
47
+ Enabled: true
48
+ Style/CaseLikeIf:
49
+ Enabled: true
50
+ Style/ExplicitBlockArgument:
51
+ Enabled: true
52
+ Style/ExponentialNotation:
53
+ Enabled: true
54
+ Style/GlobalStdStream:
55
+ Enabled: true
56
+ Style/HashAsLastArrayItem:
57
+ Enabled: true
58
+ Style/HashEachMethods:
59
+ Enabled: true
60
+ Style/HashLikeCase:
61
+ Enabled: true
62
+ Style/HashTransformKeys:
63
+ Enabled: true
64
+ Style/HashTransformValues:
65
+ Enabled: true
66
+ Style/OptionalBooleanParameter:
67
+ Enabled: true
68
+ Style/RedundantAssignment:
69
+ Enabled: true
70
+ Style/RedundantFetchBlock:
71
+ Enabled: true
72
+ Style/RedundantFileExtensionInRequire:
73
+ Enabled: true
74
+ Style/RedundantRegexpCharacterClass:
75
+ Enabled: true
76
+ Style/RedundantRegexpEscape:
77
+ Enabled: true
78
+ Style/SingleArgumentDig:
79
+ Enabled: true
80
+ Style/SlicingWithRange:
81
+ Enabled: true
@@ -1,6 +1,12 @@
1
1
  ---
2
2
  ---
3
3
  # Release History
4
+ * 1.13.0 November 23, 2020
5
+ * Add image quality interpolation; allows for variable image quality based on image size.
6
+ * Bugfix: Perform format, resize, and quality changes simultaneously rather than individually.
7
+ * Allows for actual lossless webp: simply set quality to 100.
8
+ * Improves fresh (no cached images) build times by ~15%
9
+ * Fix problems with poor image quality.
4
10
  * 1.12.0 July 30, 2020
5
11
  * Documentation overhaul. Now with 87% less scrolling!
6
12
  * Rename `markup_presets` and `media_presets` to `presets` and
@@ -35,6 +35,18 @@
35
35
  ```
36
36
  {% picture blog_index {{ post.image }} --link {{ post.url }} %}
37
37
  ```
38
+ N.B. If the image path is coming from a liquid variable then you have two problems to guard against.
39
+ * __Spaces__: you need to wrap the inner tag in "" to stop a path with spaces being interpretted as two or more arguments:
40
+ ```
41
+ {% picture blog_index "{{ post.image }}" %}
42
+ ```
43
+ * __Nulls & Blanks__: you need to wrap whole tag in a logic block to stop an uncaught Liquid exception:
44
+ ```
45
+ {% if post.image && post.image != "" %}
46
+ {% picture blog_index "{{ post.image }}" %}
47
+ {% endif %}
48
+ ```
49
+
38
50
 
39
51
  * Add arbitrary HTML attributes:
40
52
  ```
@@ -23,10 +23,10 @@ _Format:_
23
23
  _Example:_
24
24
 
25
25
  ```yaml
26
- crop: 16:9
26
+ crop: '16:9'
27
27
  media_crop:
28
- tablet: 3:2
29
- mobile: 1:1
28
+ tablet: '3:2'
29
+ mobile: '1:1'
30
30
  ```
31
31
 
32
32
  Crop geometry, given either generally or for specific media presets. The
@@ -4,16 +4,61 @@ sort: 6
4
4
 
5
5
  # Image Quality
6
6
 
7
+ Image quality can be as simple as a constant for all images, or can be varied based on image width
8
+ and output format.
9
+
10
+ ```note
11
+ For lossless webp images, set quality to 100.
12
+ ```
13
+
14
+
7
15
  ## Quality
8
16
 
17
+ ### Constant
18
+
9
19
  _Format:_ `quality: 0 <= integer <= 100`
10
20
 
11
21
  _Example:_ `quality: 80`
12
22
 
13
23
  _Default:_ `75`
14
24
 
15
- Specify an image compression level for all image formats (where it makes
16
- sense, anyway).
25
+ Specify an image compression level for all widths, all image formats.
26
+
27
+ ### Variable
28
+
29
+ _Format:_
30
+
31
+ ```yaml
32
+ quality:
33
+ (image width): (quality setting)
34
+ (image width): (quality setting)
35
+ ```
36
+
37
+ _Example:_
38
+
39
+ ```yaml
40
+ quality:
41
+ 1000: 65
42
+ 300: 100
43
+ ```
44
+
45
+ Set a variable image quality, based on image width. Provide exactly 2 image widths and associated
46
+ quality settings. Quality will be calculated as follows:
47
+
48
+ * For images smaller than the lowest image width, the setting for the lowest width is used.
49
+ * For images larger than the highest image width, the setting for the highest width is used.
50
+ * For images in between the 2, the quality setting will be linearly interpolated to some value in
51
+ between.
52
+
53
+ ![](quality_width_graph.png)
54
+
55
+ Using this setting, you can get away with more compression on high pixel density screens without
56
+ sacrificing image quality for low-density screens. Taking the example settings above:
57
+
58
+ * A 1500px image will use a quality of 65.
59
+ * A 200px image will use a quality of 100.
60
+ * A 500px image will use a quality of 90.
61
+
17
62
 
18
63
  ## Format Quality
19
64
 
@@ -25,6 +70,14 @@ sort: 6
25
70
  (...)
26
71
  ```
27
72
 
73
+ ```yaml
74
+ format_quality:
75
+ (format):
76
+ (image width): (quality setting)
77
+ (image width): (quality setting)
78
+ ```
79
+
80
+
28
81
  _Example:_
29
82
 
30
83
  ```yaml
@@ -34,10 +87,19 @@ sort: 6
34
87
  webp: 55
35
88
  ```
36
89
 
90
+ ```yaml
91
+ format_quality:
92
+ jpg:
93
+ 1000: 65
94
+ 300: 100
95
+ (...)
96
+ ```
97
+
37
98
  _Default:_ quality setting
38
99
 
39
- Specify quality settings for various image formats, allowing you to take
40
- advantage of webp's better compression algorithm without trashing your jpg
41
- images (for example). If you don't give a setting for a particular format
42
- it'll fall back to the `quality` setting above, and if you don't set _that_
43
- it'll default to 75.
100
+ Specify quality settings for various image formats, allowing you to take advantage of webp's
101
+ better compression algorithm without trashing your jpg images (for example). If you don't give a
102
+ setting for a particular format it'll fall back to the `quality` setting above, and if you don't
103
+ set _that_ it'll default to 75.
104
+
105
+ Note that this setting can accept the same variable quality setting format as the basic `quality` setting.
@@ -33,14 +33,14 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency 'nokogiri', '~> 1.10'
34
34
  spec.add_development_dependency 'pry'
35
35
  spec.add_development_dependency 'rake', '~> 12.3'
36
- spec.add_development_dependency 'rubocop'
36
+ spec.add_development_dependency 'rubocop', '~> 0.8'
37
37
  spec.add_development_dependency 'simplecov'
38
38
  spec.add_development_dependency 'solargraph'
39
39
 
40
40
  spec.add_dependency 'addressable', '~> 2.6'
41
- spec.add_dependency 'mime-types', '~> 3'
42
- spec.add_dependency 'mini_magick', '~> 4'
43
- spec.add_dependency 'objective_elements', '~> 1.1.2'
41
+ spec.add_dependency 'mime-types', '~> 3.0'
42
+ spec.add_dependency 'mini_magick', '~> 4.0'
43
+ spec.add_dependency 'objective_elements', '~> 1.1'
44
44
 
45
45
  spec.add_runtime_dependency 'jekyll', '< 5'
46
46
  end
@@ -1,15 +1,13 @@
1
1
  require 'jekyll'
2
2
  require 'objective_elements'
3
3
 
4
- require_relative 'jekyll_picture_tag/generated_image'
4
+ require_relative 'jekyll_picture_tag/cache'
5
+ require_relative 'jekyll_picture_tag/images'
5
6
  require_relative 'jekyll_picture_tag/instructions'
6
7
  require_relative 'jekyll_picture_tag/output_formats'
7
- require_relative 'jekyll_picture_tag/source_image'
8
+ require_relative 'jekyll_picture_tag/router'
8
9
  require_relative 'jekyll_picture_tag/srcsets'
9
10
  require_relative 'jekyll_picture_tag/utils'
10
- require_relative 'jekyll_picture_tag/img_uri'
11
- require_relative 'jekyll_picture_tag/router'
12
- require_relative 'jekyll_picture_tag/cache'
13
11
 
14
12
  # Title: Jekyll Picture Tag
15
13
  # Authors: Rob Wierzbowski : @robwierzbowski
@@ -0,0 +1,3 @@
1
+ require_relative 'images/generated_image'
2
+ require_relative 'images/img_uri'
3
+ require_relative 'images/source_image'
@@ -35,8 +35,8 @@ module PictureTag
35
35
  @name ||= "#{@source.base_name}-#{@width}-#{id}.#{@format}"
36
36
  end
37
37
 
38
- # https://example.com/assets/images/myimage-100-123abc.jpg
39
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38
+ # https://example.com/assets/somefolder/myimage-100-123abc.jpg
39
+ # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
40
40
  def uri
41
41
  ImgURI.new(name).to_s
42
42
  end
@@ -103,25 +103,8 @@ module PictureTag
103
103
 
104
104
  def generate_image
105
105
  puts 'Generating new image file: ' + name
106
- process_image
107
- write_image
108
- end
109
-
110
- def quality
111
- PictureTag.quality(@format)
112
- end
113
-
114
- def process_image
115
- image.combine_options do |i|
116
- i.resize "#{@width}x"
117
- i.strip
118
- end
119
106
 
120
- image.format @format
121
- image.quality quality
122
- end
123
-
124
- def write_image
107
+ image.format(@format, 0, { resize: "#{@width}x", quality: quality })
125
108
  FileUtils.mkdir_p(File.dirname(absolute_filename))
126
109
 
127
110
  image.write absolute_filename
@@ -129,6 +112,10 @@ module PictureTag
129
112
  FileUtils.chmod(0o644, absolute_filename)
130
113
  end
131
114
 
115
+ def quality
116
+ PictureTag.quality(@format, @width)
117
+ end
118
+
132
119
  def process_format(format)
133
120
  if format.casecmp('original').zero?
134
121
  @source.ext
@@ -40,9 +40,24 @@ module PictureTag
40
40
  setting_lookup('widths', 'media', media)
41
41
  end
42
42
 
43
- # Image quality setting, possibly dependent on format.
44
- def quality(format = nil)
45
- setting_lookup('quality', 'format', format)
43
+ # Image quality setting. Surprisingly complicated; can depend on both format and width.
44
+ def quality(format = nil, width = nil)
45
+ setting = setting_lookup('quality', 'format', format)
46
+
47
+ return setting unless setting.is_a? Hash
48
+
49
+ parse_quality_hash(setting, width)
50
+ end
51
+
52
+ def parse_quality_hash(points, width)
53
+ # The points can be given in any order.
54
+ low, high = *points.keys.map(&:to_i).sort
55
+
56
+ case width
57
+ when 0..low then points[low]
58
+ when low..high then Utils.interpolate(points.keys, points.values, width)
59
+ when high..999_999 then points[high]
60
+ end
46
61
  end
47
62
 
48
63
  # Gravity setting (for imagemagick cropping)
@@ -108,8 +108,8 @@ module PictureTag
108
108
  preset.nomarkdown?
109
109
  end
110
110
 
111
- def quality(format)
112
- preset.quality(format)
111
+ def quality(format, width)
112
+ preset.quality(format, width)
113
113
  end
114
114
  end
115
115
  end
@@ -63,6 +63,20 @@ module PictureTag
63
63
  def titleize(input)
64
64
  input.split('_').map(&:capitalize).join
65
65
  end
66
+
67
+ # Linear interpolator. Pass it 2 values in the x array, 2 values
68
+ # in the y array, and an x value, returns a y value.
69
+ def interpolate(xvals, yvals, xval)
70
+ xvals.map!(&:to_f)
71
+ yvals.map!(&:to_f)
72
+
73
+ # Slope
74
+ m = (yvals.last - yvals.first) / (xvals.last - xvals.first)
75
+ # Value of y when x=0
76
+ b = yvals.first - (m * xvals.first)
77
+ # y = mx + b
78
+ (m * xval) + b
79
+ end
66
80
  end
67
81
  end
68
82
  end
@@ -1,3 +1,3 @@
1
1
  module PictureTag
2
- VERSION = '1.12.0'.freeze
2
+ VERSION = '1.13.0'.freeze
3
3
  end
data/readme.md CHANGED
@@ -39,24 +39,21 @@ https://rbuchberger.github.io/jekyll_picture_tag/
39
39
 
40
40
  ## Changelog:
41
41
 
42
- https://rbuchberger.github.io/jekyll_picture_tag/releases
42
+ https://rbuchberger.github.io/jekyll_picture_tag/devs/releases
43
43
 
44
44
  Latest versions:
45
45
 
46
- * 1.10.1 July 2, 2020
47
- * Bugfix for erroneously regenerated images
48
- * 1.10.2 July 6, 2020
49
- * Bugfix for fallback image files not actually getting generated
50
- * 1.11.0 July 27, 2020
51
- * **Width and height attribute support!** Begone, page reflow.
52
- * Cache image information between builds
53
- * Change image naming format. This update will trigger all images to be regenerated, so you may
54
- want to delete your generated images folder beforehand.
46
+ * 1.13.0 November 23, 2020
47
+ * Add image quality interpolation; allows for variable image quality based on image size.
48
+ * Bugfix: Perform format, resize, and quality changes simultaneously rather than individually.
49
+ * Allows for actual lossless webp: simply set quality to 100.
50
+ * Improves fresh (no cached images) build times by ~15%
51
+ * Fix problems with poor image quality.
55
52
 
56
53
  ## Help Wanted
57
54
 
58
55
  Writing code is only part of the job; often the harder part is knowing what needs to be changed. Any
59
56
  and all feedback is greatly appreciated, especially in regards to documentation. What are your pain
60
57
  points? See the [contributing
61
- guidelines](https://rbuchberger.github.io/jekyll_picture_tag/contributing), or the
58
+ guidelines](https://rbuchberger.github.io/jekyll_picture_tag/devs/contributing), or the
62
59
  [issues](https://github.com/rbuchberger/jekyll_picture_tag/issues) page for more.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_picture_tag
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.0
4
+ version: 1.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Wierzbowski
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-07-29 00:00:00.000000000 Z
13
+ date: 2020-11-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -100,16 +100,16 @@ dependencies:
100
100
  name: rubocop
101
101
  requirement: !ruby/object:Gem::Requirement
102
102
  requirements:
103
- - - ">="
103
+ - - "~>"
104
104
  - !ruby/object:Gem::Version
105
- version: '0'
105
+ version: '0.8'
106
106
  type: :development
107
107
  prerelease: false
108
108
  version_requirements: !ruby/object:Gem::Requirement
109
109
  requirements:
110
- - - ">="
110
+ - - "~>"
111
111
  - !ruby/object:Gem::Version
112
- version: '0'
112
+ version: '0.8'
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: simplecov
115
115
  requirement: !ruby/object:Gem::Requirement
@@ -158,42 +158,42 @@ dependencies:
158
158
  requirements:
159
159
  - - "~>"
160
160
  - !ruby/object:Gem::Version
161
- version: '3'
161
+ version: '3.0'
162
162
  type: :runtime
163
163
  prerelease: false
164
164
  version_requirements: !ruby/object:Gem::Requirement
165
165
  requirements:
166
166
  - - "~>"
167
167
  - !ruby/object:Gem::Version
168
- version: '3'
168
+ version: '3.0'
169
169
  - !ruby/object:Gem::Dependency
170
170
  name: mini_magick
171
171
  requirement: !ruby/object:Gem::Requirement
172
172
  requirements:
173
173
  - - "~>"
174
174
  - !ruby/object:Gem::Version
175
- version: '4'
175
+ version: '4.0'
176
176
  type: :runtime
177
177
  prerelease: false
178
178
  version_requirements: !ruby/object:Gem::Requirement
179
179
  requirements:
180
180
  - - "~>"
181
181
  - !ruby/object:Gem::Version
182
- version: '4'
182
+ version: '4.0'
183
183
  - !ruby/object:Gem::Dependency
184
184
  name: objective_elements
185
185
  requirement: !ruby/object:Gem::Requirement
186
186
  requirements:
187
187
  - - "~>"
188
188
  - !ruby/object:Gem::Version
189
- version: 1.1.2
189
+ version: '1.1'
190
190
  type: :runtime
191
191
  prerelease: false
192
192
  version_requirements: !ruby/object:Gem::Requirement
193
193
  requirements:
194
194
  - - "~>"
195
195
  - !ruby/object:Gem::Version
196
- version: 1.1.2
196
+ version: '1.1'
197
197
  - !ruby/object:Gem::Dependency
198
198
  name: jekyll
199
199
  requirement: !ruby/object:Gem::Requirement
@@ -284,6 +284,7 @@ files:
284
284
  - docs/users/presets/media_queries.md
285
285
  - docs/users/presets/nomarkdown_override.md
286
286
  - docs/users/presets/pixel_ratio_srcsets.md
287
+ - docs/users/presets/quality_width_graph.png
287
288
  - docs/users/presets/width_height_attributes.md
288
289
  - docs/users/presets/width_srcsets.md
289
290
  - jekyll-picture-tag.gemspec
@@ -296,8 +297,10 @@ files:
296
297
  - lib/jekyll_picture_tag/cache/source.rb
297
298
  - lib/jekyll_picture_tag/defaults/global.yml
298
299
  - lib/jekyll_picture_tag/defaults/presets.yml
299
- - lib/jekyll_picture_tag/generated_image.rb
300
- - lib/jekyll_picture_tag/img_uri.rb
300
+ - lib/jekyll_picture_tag/images.rb
301
+ - lib/jekyll_picture_tag/images/generated_image.rb
302
+ - lib/jekyll_picture_tag/images/img_uri.rb
303
+ - lib/jekyll_picture_tag/images/source_image.rb
301
304
  - lib/jekyll_picture_tag/instructions.rb
302
305
  - lib/jekyll_picture_tag/instructions/arg_splitter.rb
303
306
  - lib/jekyll_picture_tag/instructions/configuration.rb
@@ -318,7 +321,6 @@ files:
318
321
  - lib/jekyll_picture_tag/output_formats/picture.rb
319
322
  - lib/jekyll_picture_tag/output_formats/readme.md
320
323
  - lib/jekyll_picture_tag/router.rb
321
- - lib/jekyll_picture_tag/source_image.rb
322
324
  - lib/jekyll_picture_tag/srcsets.rb
323
325
  - lib/jekyll_picture_tag/srcsets/basic.rb
324
326
  - lib/jekyll_picture_tag/srcsets/pixel_ratio.rb