shrine-blurhash 0.0.1 → 0.1.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: d996837d159a23efc83e220f7f937ad440bf3acfe98093f7483b4e08de221091
4
- data.tar.gz: d956efac6992fff592f1b37c46fbbb9bdfe2b09ef5dfb3414feee57eee9adc5b
3
+ metadata.gz: 9f4650238faaadb15dffee5a1ac789edb8be01357bd46591d2cb4fbab32890d1
4
+ data.tar.gz: e1f9853635ccd673feacad7ab25d8a36a632ffeba564911c653e4fa32bb97039
5
5
  SHA512:
6
- metadata.gz: 32e9956e147d75ab3bb218c58e14dd46eeb4878a9d91812e064d17cb23d7210aebce352280f64b775849231a0d40a032b3f82418dd16d6f83be7c68da71976bc
7
- data.tar.gz: 27c0e803e7f930c70629ec1a70a6aa256c05eea6f6fbf65cccc9e348f78d7027555d85d5e72d03d5409c2f23f7826fc3f2fd0891cc1a48f419948a6f4b2171ef
6
+ metadata.gz: 2ef4077470e95bed536756b304d175a9650bf34b2a2061cc6d8e731560cfdd2e5e5240600181b5a522f4fb454a2b943ad8a62d9314b0bc442663ffbe2ed0c969
7
+ data.tar.gz: 382ab14aef4378e3fa1797fa1937bf254efb052443b8a15f274e0e776cc5062e8f1c3019c47c4d85f070c6fe97d1f626ae1c56f5b0c03f609c44746a33d9aeb0
data/README.md CHANGED
@@ -44,7 +44,7 @@ end
44
44
 
45
45
  ### ```components```
46
46
 
47
- Type: `[components_x, components_y]`
47
+ Type: `[components_x, components_y]` or a `Proc`
48
48
  Default: `[4, 3]`
49
49
 
50
50
  ```ruby
@@ -53,6 +53,12 @@ plugin :blurhash, components: [2, 2]
53
53
 
54
54
  This allows you to customize the number of components on each axis for the Blurhash algorithm. The visual result will look like a grid of `X * Y` blurred colors.
55
55
 
56
+ You can also pass a proc which receive the width and height and calculate the components on-the-fly:
57
+
58
+ ```ruby
59
+ plugin :blurhash, components: ->(width, height) { [width / 600, height / 600] }
60
+ ```
61
+
56
62
  ### `resize_to`
57
63
 
58
64
  Type: `Integer` or `nil`
@@ -46,8 +46,8 @@ class Shrine
46
46
  blurhash = instrument_blurhash(io) do
47
47
  pixels = extractor.call(*args)
48
48
 
49
- components = opts[:blurhash][:components]
50
- ::Blurhash.encode(pixels[:width], pixels[:height], pixels[:pixels], x_comp: components[0], y_comp: components[1])
49
+ x_comp, y_comp = components_for(pixels[:width], pixels[:height])
50
+ ::Blurhash.encode(pixels[:width], pixels[:height], pixels[:pixels], x_comp: x_comp, y_comp: y_comp)
51
51
  end
52
52
 
53
53
  io.rewind
@@ -73,6 +73,13 @@ class Shrine
73
73
 
74
74
  private
75
75
 
76
+ def components_for(width, height)
77
+ if opts[:blurhash][:components].respond_to?(:call)
78
+ opts[:blurhash][:components].call(width, height)
79
+ else opts[:blurhash][:components]
80
+ end
81
+ end
82
+
76
83
  # Sends a `blurhash.shrine` event for instrumentation plugin.
77
84
  def instrument_blurhash(io, &block)
78
85
  return yield unless respond_to?(:instrument)
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "shrine-blurhash"
5
- gem.version = "0.0.1"
5
+ gem.version = "0.1.0"
6
6
 
7
7
  gem.required_ruby_version = ">= 2.5"
8
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shrine-blurhash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renaud Chaput
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-27 00:00:00.000000000 Z
11
+ date: 2022-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: blurhash
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description:
83
+ description:
84
84
  email:
85
85
  - renchap@gmail.com
86
86
  executables: []
@@ -94,7 +94,7 @@ homepage: https://github.com/renchap/shrine-blurhash
94
94
  licenses:
95
95
  - MIT
96
96
  metadata: {}
97
- post_install_message:
97
+ post_install_message:
98
98
  rdoc_options: []
99
99
  require_paths:
100
100
  - lib
@@ -109,8 +109,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  requirements: []
112
- rubygems_version: 3.0.3
113
- signing_key:
112
+ rubygems_version: 3.3.7
113
+ signing_key:
114
114
  specification_version: 4
115
115
  summary: Shrine plugin to compute Blurhash on image attachments
116
116
  test_files: []