shrine-blurhash 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/shrine/plugins/blurhash.rb +16 -1
- data/shrine-blurhash.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a47804bcc600a50af846d40aa7c3a5fdff9eb589fa828afe82fad83d83817e6
|
4
|
+
data.tar.gz: ca6bd00f5b85fd98932747b40d60b5b200620e37c1516d0620d0dba532863cdd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17f1a9589a435353739bc2f74a862e96cec84850054877025d5da7d65985244c4f1a96bcbc831a4904c8e6ea7dec55fcde62e0ee3bd49c828266a2127ab5c190
|
7
|
+
data.tar.gz: e0db94dca1055e833aa51385e17240747d3666e527fa11331b010a1dd6cd87ce42a2c02383f68101deb62881dcfbd259050ecde6e0a4fc7a91bc77d0a0df5e9e
|
@@ -128,10 +128,25 @@ class Shrine
|
|
128
128
|
|
129
129
|
begin
|
130
130
|
Shrine.with_file(io) do |file|
|
131
|
-
image = Vips::Image.new_from_file(file.path, access: :sequential)
|
131
|
+
image = Vips::Image.new_from_file(file.path, access: :sequential).colourspace(:srgb)
|
132
132
|
image = image.resize(resize_to.fdiv(image.width), vscale: resize_to.fdiv(image.height)) if resize_to
|
133
133
|
image = image.flatten if image.has_alpha?
|
134
134
|
|
135
|
+
# Blurhash requires exactly 3 bands
|
136
|
+
case image.bands
|
137
|
+
when 1
|
138
|
+
# Duplicate the only band into 2 new bands
|
139
|
+
image = image.bandjoin(Array.new(3 - image.bands, image))
|
140
|
+
when 2
|
141
|
+
# Duplicate the first band into a third band
|
142
|
+
image = image.bandjoin(image.extract_band(0))
|
143
|
+
when 3
|
144
|
+
# Do nothing, band count is already correct
|
145
|
+
else
|
146
|
+
# Only keep the first 3 bands
|
147
|
+
image = image.extract_band(0, n: 3)
|
148
|
+
end
|
149
|
+
|
135
150
|
{
|
136
151
|
width: image.width,
|
137
152
|
height: image.height,
|
data/shrine-blurhash.gemspec
CHANGED