shrine-blurhash 0.2.1 → 0.2.2

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
  SHA256:
3
- metadata.gz: 39c6d8fd3e19a78ac91d21d5adebb1a834fafcb80c1493b281a132f6d9880201
4
- data.tar.gz: e4e7faea183a676725b610353fc8d052417fdf1bdd58544ed73647b87e9f777c
3
+ metadata.gz: 8a47804bcc600a50af846d40aa7c3a5fdff9eb589fa828afe82fad83d83817e6
4
+ data.tar.gz: ca6bd00f5b85fd98932747b40d60b5b200620e37c1516d0620d0dba532863cdd
5
5
  SHA512:
6
- metadata.gz: 11e4c2bf34926fc35e6bc18b75c6642eeda93ecda13e3c8a767ce0e776a428e4a6d2fb05833f7e9e42701941dc5dc8c9acf34adf933c4afa05b5979e6aaa75f7
7
- data.tar.gz: 595c3ae789fd7267d195bec699893cb7b56972607b301a3a9da6d5abb566fadad0cc8447b78323324b0e970d33314b81e1f0f92392b1c4d288a76be0e79117fa
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,
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "shrine-blurhash"
5
- gem.version = "0.2.1"
5
+ gem.version = "0.2.2"
6
6
 
7
7
  gem.required_ruby_version = ">= 3.1"
8
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shrine-blurhash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renaud Chaput