shrine-blurhash 0.2.1 → 0.2.3
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 +4 -4
- data/lib/shrine/plugins/blurhash.rb +28 -23
- data/shrine-blurhash.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1775a3abaa4ff444b6320adc7d3eb5125d2dbd20d32756166397667486ef8070
|
4
|
+
data.tar.gz: fa63be0fc7a4b6dc69074578762859d337e8b2f476c2e06603261b5831ae44a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c443841b6c082c801ac10a5b32484cd51023e8516e3c4cfceedb8e0c1383a72517e992ed673d8325a52282065ebd9c9c8c7407f53a51c15662b278393b21530
|
7
|
+
data.tar.gz: 267ab27ff58d5c7e9ff3948dfa0d165d39fb6ec12da8dae17500ef22ecf22964ba7db32596fe69d1197dc93d56df0742e5ff03ea47e9695ed4387547df2cf16b
|
@@ -53,6 +53,9 @@ class Shrine
|
|
53
53
|
io.rewind
|
54
54
|
|
55
55
|
blurhash
|
56
|
+
rescue StandardError => e
|
57
|
+
opts[:blurhash][:on_error].call(e)
|
58
|
+
nil
|
56
59
|
end
|
57
60
|
|
58
61
|
# Returns a hash of built-in pixels extractors, where keys are
|
@@ -66,9 +69,7 @@ class Shrine
|
|
66
69
|
|
67
70
|
# Returns callable pixels extractor object.
|
68
71
|
def pixels_extractor(name)
|
69
|
-
|
70
|
-
|
71
|
-
PixelsExtractor.new(name, on_error: on_error).method(:call)
|
72
|
+
PixelsExtractor.new(name).method(:call)
|
72
73
|
end
|
73
74
|
|
74
75
|
private
|
@@ -106,13 +107,12 @@ class Shrine
|
|
106
107
|
class PixelsExtractor
|
107
108
|
SUPPORTED_EXTRACTORS = [:ruby_vips].freeze
|
108
109
|
|
109
|
-
def initialize(tool
|
110
|
+
def initialize(tool)
|
110
111
|
unless SUPPORTED_EXTRACTORS.include?(tool)
|
111
112
|
raise Error, "unknown pixel extractor #{tool.inspect}, supported extractors are: #{SUPPORTED_EXTRACTORS.join(',')}"
|
112
113
|
end
|
113
114
|
|
114
115
|
@tool = tool
|
115
|
-
@on_error = on_error
|
116
116
|
end
|
117
117
|
|
118
118
|
def call(io, resize_to)
|
@@ -126,26 +126,31 @@ class Shrine
|
|
126
126
|
def extract_with_ruby_vips(io, resize_to)
|
127
127
|
require "vips"
|
128
128
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
129
|
+
Shrine.with_file(io) do |file|
|
130
|
+
image = Vips::Image.new_from_file(file.path, access: :sequential).colourspace(:srgb)
|
131
|
+
image = image.resize(resize_to.fdiv(image.width), vscale: resize_to.fdiv(image.height)) if resize_to
|
132
|
+
image = image.flatten if image.has_alpha?
|
133
|
+
# Blurhash requires exactly 3 bands
|
134
|
+
case image.bands
|
135
|
+
when 1
|
136
|
+
# Duplicate the only band into 2 new bands
|
137
|
+
image = image.bandjoin(Array.new(3 - image.bands, image))
|
138
|
+
when 2
|
139
|
+
# Duplicate the first band into a third band
|
140
|
+
image = image.bandjoin(image.extract_band(0))
|
141
|
+
when 3
|
142
|
+
# Do nothing, band count is already correct
|
143
|
+
else
|
144
|
+
# Only keep the first 3 bands
|
145
|
+
image = image.extract_band(0, n: 3)
|
140
146
|
end
|
141
|
-
rescue Vips::Error => e
|
142
|
-
on_error(e)
|
143
|
-
end
|
144
|
-
end
|
145
147
|
|
146
|
-
|
147
|
-
|
148
|
-
|
148
|
+
{
|
149
|
+
width: image.width,
|
150
|
+
height: image.height,
|
151
|
+
pixels: image.to_a.flatten,
|
152
|
+
}
|
153
|
+
end
|
149
154
|
end
|
150
155
|
end
|
151
156
|
end
|
data/shrine-blurhash.gemspec
CHANGED
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.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Renaud Chaput
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: blurhash
|