shrine-thumbhash 0.1.0 → 0.2.0

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: 56d67f222347d85c3a9a72603effe992cbbf5538fa7aeaf1e63d06859c06064c
4
- data.tar.gz: 7d808dd14643b00720a42b6c49bdc5aea910902135d4005c92a601e46c89789d
3
+ metadata.gz: b41c1fac9cd933c44eb7f8867dcf0d6d5f66853ad22ec975b7a127866d2dab57
4
+ data.tar.gz: 0a5251f90a8d0697afd701151a5af94e994b0b073d98cd897a22df5714608b87
5
5
  SHA512:
6
- metadata.gz: f5b3fff17ba9bd77a9fa1755018a2a219b0dc87a32e7d868dd468bad3890b90695a7a5985265971fe0598378b792d60d0c4f5ca8911bd2b71e88360442d3498d
7
- data.tar.gz: fbc81b2d279f6c169e85fa99b7338fe449fac80e78fc1d55e9d7e609bf3af7168240cf83e7c04c7f5c4509c25ae8dd73f94a7a196146783ab48ff4c0902c7a7f
6
+ metadata.gz: 2307fbd23a1cff609eadfc9d99a20e126f3fe3fa37d2b5914b2a98f95b50cb4eb07d1584ba7ae1c3bbaec1c422d76a130c2b5b216e861a160e1f52a64a515c1f
7
+ data.tar.gz: 93722745374a9f0cf9674cc9e4fff90b78655d88a021148bbaffe4e86c9f3251435cf70d7e51f5cf587ec7fbda5c1898fef80cbeb126ebf7ff3210299ce8aaf0
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in shrine-thumbhash.gemspec
6
6
  gemspec
7
7
 
8
+ gem "mini_magick", "~> 4.0"
8
9
  gem "rake", "~> 13.0"
9
10
  gem "rspec", "~> 3.0"
10
11
  gem "rubocop", "~> 1.21"
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 fusagiko / takayamaki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -14,6 +14,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
14
14
 
15
15
  ## Requirements
16
16
  - [ruby-vips gem](https://rubygems.org/gems/ruby-vips) (default or when you specify `:ruby_vips` to image_loader option)
17
+ - [mini_magick gem](https://rubygems.org/gems/mini_magick) (When you specify `:mini_magick` to image_loader option)
17
18
 
18
19
  ## Usage
19
20
 
@@ -40,7 +41,7 @@ uploaded_file.thumbhash_urlsafe
40
41
  ### padding
41
42
  When specify false, thumbhash will be without padding.
42
43
 
43
- Default: true
44
+ Default: `true`
44
45
  ```ruby
45
46
  Shrine.plugin :thumbhash, padding: false
46
47
  ... # omit
@@ -55,8 +56,9 @@ A ruby object be used for loading and resizeing image.
55
56
  When you choose from our implementations, you can specify them by Symbol.
56
57
 
57
58
  - `:ruby_vips`
59
+ - `:mini_magick`
58
60
 
59
- Default: :ruby_vips
61
+ Default: `:ruby_vips`
60
62
 
61
63
  If you want to use something other than our implementations, you can implement it yourself.
62
64
  See `lib/shrine/plugins/image_loader/ruby_vips.rb`.
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../image"
4
+ require "mini_magick"
5
+
6
+ class Shrine # :nodoc:
7
+ module Plugins # :nodoc:
8
+ module Thumbhash # :nodoc:
9
+ module ImageLoader # :nodoc:
10
+ module MiniMagick # :nodoc:
11
+ def self.call(io)
12
+ image = load_image(io)
13
+ image = resize_image(image)
14
+ Thumbhash::Image.new(
15
+ image.width,
16
+ image.height,
17
+ repack_pixels_to_flattened_rgba_array(image)
18
+ )
19
+ end
20
+
21
+ def self.load_image(io)
22
+ ::MiniMagick::Image.read(io)
23
+ end
24
+
25
+ def self.resize_image(image)
26
+ return image if image.width <= 100 && image.height <= 100
27
+
28
+ image.resize("100x100")
29
+ end
30
+
31
+ def self.repack_pixels_to_flattened_rgba_array(image)
32
+ image.get_pixels("RGBA").flatten
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -3,7 +3,7 @@
3
3
  class Shrine
4
4
  module Plugins
5
5
  module Thumbhash
6
- VERSION = "0.1.0"
6
+ VERSION = "0.2.0"
7
7
  end
8
8
  end
9
9
  end
@@ -18,10 +18,14 @@ class Shrine # :nodoc:
18
18
  end
19
19
 
20
20
  def self.configure_image_loader(opts)
21
- return unless opts[:image_loader] == :ruby_vips
22
-
23
- require_relative "image_loader/ruby_vips"
24
- opts[:image_loader] = Shrine::Plugins::Thumbhash::ImageLoader::RubyVips
21
+ case opts[:image_loader]
22
+ when :mini_magick
23
+ require_relative "thumbhash/image_loader/mini_magick"
24
+ opts[:image_loader] = Shrine::Plugins::Thumbhash::ImageLoader::MiniMagick
25
+ else
26
+ require_relative "thumbhash/image_loader/ruby_vips"
27
+ opts[:image_loader] = Shrine::Plugins::Thumbhash::ImageLoader::RubyVips
28
+ end
25
29
  end
26
30
 
27
31
  module ClassMethods # :nodoc:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shrine-thumbhash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - takayamaki / fusagiko
@@ -48,11 +48,13 @@ files:
48
48
  - ".rspec"
49
49
  - ".rubocop.yml"
50
50
  - Gemfile
51
+ - LICENSE
51
52
  - README.md
52
53
  - Rakefile
53
- - lib/shrine/plugins/image.rb
54
- - lib/shrine/plugins/image_loader/ruby_vips.rb
55
54
  - lib/shrine/plugins/thumbhash.rb
55
+ - lib/shrine/plugins/thumbhash/image.rb
56
+ - lib/shrine/plugins/thumbhash/image_loader/mini_magick.rb
57
+ - lib/shrine/plugins/thumbhash/image_loader/ruby_vips.rb
56
58
  - lib/shrine/plugins/thumbhash/version.rb
57
59
  - shrine-thumbhash.gemspec
58
60
  - sig/shrine/plugins/thumbhash.rbs