shrine-thumbhash 0.1.0 → 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/Gemfile +1 -0
- data/LICENSE +21 -0
- data/README.md +4 -2
- data/lib/shrine/plugins/thumbhash/image_loader/mini_magick.rb +38 -0
- data/lib/shrine/plugins/thumbhash/version.rb +1 -1
- data/lib/shrine/plugins/thumbhash.rb +8 -4
- metadata +5 -3
- /data/lib/shrine/plugins/{image.rb → thumbhash/image.rb} +0 -0
- /data/lib/shrine/plugins/{image_loader → thumbhash/image_loader}/ruby_vips.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b41c1fac9cd933c44eb7f8867dcf0d6d5f66853ad22ec975b7a127866d2dab57
|
4
|
+
data.tar.gz: 0a5251f90a8d0697afd701151a5af94e994b0b073d98cd897a22df5714608b87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2307fbd23a1cff609eadfc9d99a20e126f3fe3fa37d2b5914b2a98f95b50cb4eb07d1584ba7ae1c3bbaec1c422d76a130c2b5b216e861a160e1f52a64a515c1f
|
7
|
+
data.tar.gz: 93722745374a9f0cf9674cc9e4fff90b78655d88a021148bbaffe4e86c9f3251435cf70d7e51f5cf587ec7fbda5c1898fef80cbeb126ebf7ff3210299ce8aaf0
|
data/Gemfile
CHANGED
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:
|
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
|
@@ -18,10 +18,14 @@ class Shrine # :nodoc:
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.configure_image_loader(opts)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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.
|
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
|
File without changes
|
File without changes
|