shrine-blurhash 0.0.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -2
- data/lib/shrine/plugins/blurhash.rb +10 -2
- data/shrine-blurhash.gemspec +3 -3
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31499fb6782c8196f5e50a1a8f1b0a4fc998c0bea417be14bb44f21ce4231fed
|
4
|
+
data.tar.gz: 61658ddfad136925c5e162e3be945d31ec63c867389b92173e583ae328a26401
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3948c77c0b720439c9e7066c6cf9870ce22b2a918d9f8d031bb7f7b8ab3acb64d0583a6b8ad0ade1b1a732a678724751f953f5f2def01eff8a9dd6ddca7c8fd
|
7
|
+
data.tar.gz: 51131b0613123598d50668ecc8be4b9415aeb94c075bbaf4bae4b31da29bdd643c8100620e16dc7f8f1613fa9b98ba96de7c53af8cf6a649d2a6e33562fcbc9e
|
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`
|
@@ -72,7 +78,7 @@ You can either specify the target size or `nil` to disable image resizing comple
|
|
72
78
|
Type: `symbol` or `lambda`
|
73
79
|
|
74
80
|
```ruby
|
75
|
-
plugin :blurhash, extractor: :
|
81
|
+
plugin :blurhash, extractor: :ruby_vips
|
76
82
|
```
|
77
83
|
|
78
84
|
Supported extractors:
|
@@ -46,8 +46,8 @@ class Shrine
|
|
46
46
|
blurhash = instrument_blurhash(io) do
|
47
47
|
pixels = extractor.call(*args)
|
48
48
|
|
49
|
-
|
50
|
-
::Blurhash.encode(pixels[:width], pixels[:height], pixels[:pixels], x_comp:
|
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)
|
@@ -123,6 +130,7 @@ class Shrine
|
|
123
130
|
Shrine.with_file(io) do |file|
|
124
131
|
image = Vips::Image.new_from_file(file.path, access: :sequential)
|
125
132
|
image = image.resize(resize_to.fdiv(image.width), vscale: resize_to.fdiv(image.height)) if resize_to
|
133
|
+
image = image.flatten if image.has_alpha?
|
126
134
|
|
127
135
|
{
|
128
136
|
width: image.width,
|
data/shrine-blurhash.gemspec
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.name = "shrine-blurhash"
|
5
|
-
gem.version = "0.0
|
5
|
+
gem.version = "0.2.0"
|
6
6
|
|
7
|
-
gem.required_ruby_version = ">=
|
7
|
+
gem.required_ruby_version = ">= 3.1"
|
8
8
|
|
9
9
|
gem.summary = "Shrine plugin to compute Blurhash on image attachments"
|
10
10
|
gem.homepage = "https://github.com/renchap/shrine-blurhash"
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.files = Dir["README.md", "LICENSE.txt", "lib/**/*.rb", "shrine-blurhash.gemspec"]
|
16
16
|
gem.require_path = "lib"
|
17
17
|
|
18
|
-
gem.add_dependency "blurhash", "~> 0.1.
|
18
|
+
gem.add_dependency "blurhash", "~> 0.1.8"
|
19
19
|
gem.add_dependency "shrine", "~> 3.0"
|
20
20
|
|
21
21
|
gem.add_development_dependency "minitest"
|
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
|
4
|
+
version: 0.2.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:
|
11
|
+
date: 2024-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: blurhash
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.1.
|
19
|
+
version: 0.1.8
|
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: 0.1.
|
26
|
+
version: 0.1.8
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: shrine
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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
|
@@ -102,15 +102,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
102
|
requirements:
|
103
103
|
- - ">="
|
104
104
|
- !ruby/object:Gem::Version
|
105
|
-
version: '
|
105
|
+
version: '3.1'
|
106
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
|
-
rubygems_version: 3.
|
113
|
-
signing_key:
|
112
|
+
rubygems_version: 3.5.3
|
113
|
+
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: Shrine plugin to compute Blurhash on image attachments
|
116
116
|
test_files: []
|