jekyll-image-size 1.1.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5c349d70b0f3e1b9a28bbd98f5e1578674bada1
4
- data.tar.gz: 7fd7a02831089b2c12b6be3bc4aa742967ce2d69
3
+ metadata.gz: 836312e259f06570779274e4e75d6f9ece276204
4
+ data.tar.gz: 9184ce60ff2709368c5f8cbcff8be7f3f5e231de
5
5
  SHA512:
6
- metadata.gz: bb3ddbdbb8bfd74715f5df06ec722995c82b747ed085e572e13ecf5a8664b22b63dc2571c52ff6c526057ccc3faf8f97bdc6f9a4645cd210d54fef9b34b07a3e
7
- data.tar.gz: c02490fe1ba1a2c0bc4a95b599262bb8138874f75ae31ccd8971dc43185f67a23349214627dfed4148baf56dc26b35511ed178ec0cdb85ea8cf7eb6266a08aa4
6
+ metadata.gz: 185260d6d4b3302e31dae0c37b5ab3116ef13ef3772d3b0cf2ff76612228eb1872c1a17f0e639ef03039e2effc9f200a629d200928d0e5be42534d0ff7107e9f
7
+ data.tar.gz: 604f4e827b1ab63580c08cecf55611a3bbd95fa3aca31fdc40a74c75fbf0850c4aff49586dcb6234c90839467cfb1c011ddbba4351ee01f73c35d6a95abda814
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jekyll-image-size (1.1.0)
4
+ jekyll-image-size (1.2.0)
5
5
  fastimage (>= 1.8)
6
6
  jekyll (>= 3.7)
7
7
 
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Jekyll-Image-Size ![travis-ci.org](https://travis-ci.org/generalui/jekyll-image-size.svg) [![Gem Version](https://badge.fury.io/rb/jekyll-image-size.svg)](https://badge.fury.io/rb/jekyll-image-size)
2
2
 
3
+ <img src="spec/data/test.jpg">
4
+
3
5
  Jekyll tag-plugin to read image sizes from static assets and output in many formats.
4
6
 
5
7
  Uses:
@@ -51,7 +53,7 @@ gif, jpeg, png, tiff, bmp, ico, cur, psd, svg, webp
51
53
  The `imagesize` takes one parameter. That parameter has the form:
52
54
 
53
55
  ```
54
- source[:format[/divide-by-number]][ rest...]
56
+ source[:format[/divide-by-number]][?uri-encoded-params][ rest...]
55
57
  ```
56
58
 
57
59
  source is a string and can be one of:
@@ -78,6 +80,11 @@ divide-by-numbers:
78
80
  * integer: 2
79
81
  * float: 2.5 or 0.5 or .5
80
82
 
83
+ uri-encoded-params:
84
+
85
+ * width=123: fix the width to the given pixels and scale the height proportionally
86
+ * height=123: fix the height to the given pixels and scale the width proportionally
87
+
81
88
  rest:
82
89
 
83
90
  * must start with a space
@@ -94,7 +101,6 @@ Format examples:
94
101
  {% imagesize source:json %} >> {width: 652, height: 435}
95
102
  {% imagesize source:array %} >> [652, 435]
96
103
  {% imagesize source:list %} >> 652, 435
97
- {% imagesize source:size/2 %} >> 326x218
98
104
  {% imagesize source:width %} >> 652
99
105
  {% imagesize source:height %} >> 435
100
106
  {% imagesize source:css %} >> width: 652px; height: 435px;
@@ -103,6 +109,14 @@ Format examples:
103
109
  {% imagesize source:img %} >> <img src='/assets/logo.jpg' width='350' height='32'>
104
110
  ```
105
111
 
112
+ Scaling examples:
113
+
114
+ ```html
115
+ {% imagesize source:size/2 %} >> 326x218
116
+ {% imagesize source:size?width=600 %} >> 600x400
117
+ {% imagesize source:size?height=200 %} >> 300x200
118
+ ```
119
+
106
120
  Image source examples:
107
121
 
108
122
  ```html
@@ -117,6 +131,7 @@ Combined examples:
117
131
  {% imagesize /assets/logo.jpg:opengraph %}
118
132
  {% imagesize /assets/logo.jpg:css/2 %}
119
133
  {% imagesize image:width/2.5 %}
134
+ {% imagesize image:height?width=500 %}
120
135
  {% imagesize /assets/logo.jpg:img alt='my alt string' %}
121
136
  # <img src='/assets/logo.jpg' width='350' height='32' alt='my alt string'>
122
137
  ```
@@ -1,5 +1,6 @@
1
1
  require "jekyll"
2
2
  require 'fastimage'
3
+ require 'cgi'
3
4
  require "jekyll-image-size/version"
4
5
 
5
6
  class ImageSizeError < StandardError; end
@@ -14,9 +15,12 @@ class ImageSizeTag < Liquid::Tag
14
15
  end
15
16
 
16
17
  def self.getImageSize(content, context = nil)
17
- if m = content.match(/^((?:[^:!]|:[^a-z])+)(?::([a-z]+)(?:\/((?:\d+|(?=\.))(?:\.\d+)?))?)?(\!)?( .*)?$/i)
18
- source, mode, scale, required, rest = m.captures
18
+ if m = content.match(/^((?:[^?:!]|:[^a-z])+)(?::([a-z]+)(?:\/((?:\d+|(?=\.))(?:\.\d+)?))?)?(\!)?(?:\?(.+))?( .*)?$/i)
19
+ source, mode, scale, required, params, rest = m.captures
19
20
 
21
+ if params
22
+ params = CGI::parse(params)
23
+ end
20
24
  else
21
25
  raise ImageSizeError.new "invalid imagesize parameter: #{content}"
22
26
  end
@@ -40,6 +44,19 @@ class ImageSizeTag < Liquid::Tag
40
44
  width = height = 0
41
45
  end
42
46
 
47
+ if params
48
+ aspect_ratio = width.to_f / height.to_f
49
+ if v = params["width"][0]
50
+ width = v.to_i
51
+ height = (width / aspect_ratio).round
52
+
53
+ elsif v = params["height"][0]
54
+ height = v.to_i
55
+ width = (height * aspect_ratio).round
56
+
57
+ end
58
+ end
59
+
43
60
  if scale
44
61
  scale = scale.to_f
45
62
  width = (width / scale).round
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module ImageSize
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-image-size
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Brinkman-Davis Delamore