rails_dominant_colors 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 +4 -4
- data/.coveralls.yml +2 -0
- data/.rubocop.yml +3 -3
- data/.travis.yml +8 -2
- data/Gemfile.lock +8 -8
- data/README.md +30 -10
- data/lib/rails_dominant_colors.rb +6 -6
- data/lib/rails_dominant_colors/base.rb +28 -11
- data/lib/rails_dominant_colors/base64.rb +2 -2
- data/lib/rails_dominant_colors/path.rb +2 -2
- data/lib/rails_dominant_colors/url.rb +2 -2
- data/lib/rails_dominant_colors/version.rb +1 -1
- data/rails_dominant_colors.gemspec +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc461431999b438497a0d90347db8c6925b3229ecc914bfc6f8a76649a145b6c
|
4
|
+
data.tar.gz: 9c2692cd8a7e6bad4289c72f9922ed9361c012646f6b0b8ee9752c4281d83fdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 853a1163cae3430115faff75aeb5fa9bb727b5e9fcfe8db3ed1dcd293f0c8e9db40ba42d216f9e4fb721a7133819f3c11bdd9652c3fab6df12ce03934cb71916
|
7
|
+
data.tar.gz: 71b484c448f706717d4c188ac296ab24b5a1ab6db5db7bcc267fb2e976af6eb17930732fdd27220cf51db5ff980662357d503b0b96eb43e2e44b56cbf3504701
|
data/.coveralls.yml
ADDED
data/.rubocop.yml
CHANGED
@@ -8,13 +8,13 @@ Layout/EmptyLineAfterGuardClause:
|
|
8
8
|
Layout/EmptyLinesAroundBlockBody:
|
9
9
|
Enabled: false
|
10
10
|
Metrics/MethodLength:
|
11
|
-
Max:
|
11
|
+
Max: 25
|
12
12
|
Metrics/BlockLength:
|
13
13
|
Max: 30
|
14
14
|
Metrics/AbcSize:
|
15
|
-
Max:
|
15
|
+
Max: 25
|
16
16
|
Metrics/CyclomaticComplexity:
|
17
|
-
Max:
|
17
|
+
Max: 25
|
18
18
|
Style/RegexpLiteral:
|
19
19
|
EnforcedStyle: percent_r
|
20
20
|
Naming/MethodParameterName:
|
data/.travis.yml
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
---
|
2
|
+
os: linux
|
2
3
|
language: ruby
|
3
4
|
cache: bundler
|
4
5
|
rvm:
|
5
|
-
- 2.
|
6
|
-
|
6
|
+
- 2.5.5
|
7
|
+
- 2.6.3
|
8
|
+
- 2.7.0
|
9
|
+
before_install: gem install bundler
|
10
|
+
before_script:
|
11
|
+
- bundle install
|
12
|
+
script: RAILS_ENV=test bundle exec rspec
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rails_dominant_colors (0.
|
4
|
+
rails_dominant_colors (0.2.0)
|
5
5
|
mini_magick (~> 4.10)
|
6
6
|
|
7
7
|
GEM
|
@@ -13,24 +13,24 @@ GEM
|
|
13
13
|
term-ansicolor (~> 1.3)
|
14
14
|
thor (>= 0.19.4, < 2.0)
|
15
15
|
tins (~> 1.6)
|
16
|
-
diff-lcs (1.
|
16
|
+
diff-lcs (1.4.4)
|
17
17
|
docile (1.3.2)
|
18
|
-
json (2.3.
|
18
|
+
json (2.3.1)
|
19
19
|
mini_magick (4.10.1)
|
20
20
|
rake (13.0.1)
|
21
21
|
rspec (3.9.0)
|
22
22
|
rspec-core (~> 3.9.0)
|
23
23
|
rspec-expectations (~> 3.9.0)
|
24
24
|
rspec-mocks (~> 3.9.0)
|
25
|
-
rspec-core (3.9.
|
26
|
-
rspec-support (~> 3.9.
|
27
|
-
rspec-expectations (3.9.
|
25
|
+
rspec-core (3.9.2)
|
26
|
+
rspec-support (~> 3.9.3)
|
27
|
+
rspec-expectations (3.9.2)
|
28
28
|
diff-lcs (>= 1.2.0, < 2.0)
|
29
29
|
rspec-support (~> 3.9.0)
|
30
30
|
rspec-mocks (3.9.1)
|
31
31
|
diff-lcs (>= 1.2.0, < 2.0)
|
32
32
|
rspec-support (~> 3.9.0)
|
33
|
-
rspec-support (3.9.
|
33
|
+
rspec-support (3.9.3)
|
34
34
|
simplecov (0.16.1)
|
35
35
|
docile (~> 1.1)
|
36
36
|
json (>= 1.8, < 3)
|
@@ -40,7 +40,7 @@ GEM
|
|
40
40
|
term-ansicolor (1.7.1)
|
41
41
|
tins (~> 1.0)
|
42
42
|
thor (1.0.1)
|
43
|
-
tins (1.
|
43
|
+
tins (1.25.0)
|
44
44
|
sync
|
45
45
|
|
46
46
|
PLATFORMS
|
data/README.md
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
# RailsDominantColors
|
2
2
|
|
3
|
-
|
4
3
|
[](https://badge.fury.io/rb/rails_dominant_colors)
|
5
|
-
[](https://codeclimate.com/github/OpenGems/rails_dominant_colors/maintainability)
|
6
5
|
[](https://travis-ci.org/OpenGems/rails_dominant_colors)
|
7
6
|
[](https://hakiri.io/github/OpenGems/rails_dominant_colors/master)
|
8
7
|

|
9
8
|
[](https://coveralls.io/github/OpenGems/rails_dominant_colors?branch=master)
|
10
9
|
|
11
|
-
|
10
|
+
A Ruby gem for extract the dominant color(s) from an image (remote image, locally image, base64 image etc...)
|
12
11
|
|
13
|
-
|
12
|
+
Get HEX(A) color(s), RGB(A) color(s) and HSL(A) color(s)
|
14
13
|
|
15
14
|
## Installation
|
16
15
|
|
@@ -30,18 +29,39 @@ Or install it yourself as:
|
|
30
29
|
|
31
30
|
## Usage
|
32
31
|
|
33
|
-
|
32
|
+
```ruby
|
33
|
+
colors = 5 # Optional, number of colors (default: 5)
|
34
|
+
|
35
|
+
dominant_colors = RailsDominantColors::Base64.new('data:image/png;base64,awesome-image', colors)
|
34
36
|
|
35
|
-
|
37
|
+
# or
|
36
38
|
|
37
|
-
|
39
|
+
RailsDominantColors::Url.new('https://awesome-url.com/awesome-image.png', colors)
|
38
40
|
|
39
|
-
|
41
|
+
# or
|
40
42
|
|
41
|
-
|
43
|
+
RailsDominantColors::Path.new('/awesome/path/awesome-image.png', colors)
|
44
|
+
|
45
|
+
# and
|
46
|
+
|
47
|
+
dominant_colors.to_hex # => ["#FF007F", "#000000", "#1C000F", "#A0004F", "#000000"]
|
48
|
+
dominant_colors.to_hex_alpha # => ["#FF007FFF", "#00000000", "#1C000FFE", "#A0004FFF", "#0000005F"]
|
49
|
+
|
50
|
+
dominant_colors.to_rgb # => [[255, 0, 127], [0, 0, 0], [28, 0, 15], [160, 0, 79], [0, 0, 0]]
|
51
|
+
dominant_colors.to_rgb_alpha # => [[255, 0, 127, 1.0], [0, 0, 0, 0.0], [28, 0, 15, 1.0], [160, 0, 79, 1.0], [0, 0, 0, 0.37]]
|
42
52
|
|
43
|
-
|
53
|
+
dominant_colors.to_hsl # => [[330, 100, 50], [0, 0, 0], [328, 100, 5], [330, 100, 31], [0, 0, 0]]
|
54
|
+
dominant_colors.to_hsl_alpha # => [[330, 100, 50, 1.0], [0, 0, 0, 0.0], [328, 100, 5, 1.0], [330, 100, 31, 1.0], [0, 0, 0, 0.37]]
|
55
|
+
|
56
|
+
# Awesome bonus
|
57
|
+
dominant_colors.to_pct # => [52.16, 37.45, 9.93, 0.35, 0.1]
|
58
|
+
|
59
|
+
```
|
60
|
+
|
61
|
+
|
62
|
+
## Contributing
|
44
63
|
|
64
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/OpenGems/rails_dominant_colors. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
|
45
65
|
|
46
66
|
## License
|
47
67
|
|
@@ -7,16 +7,16 @@ require 'rails_dominant_colors/url'
|
|
7
7
|
|
8
8
|
module RailsDominantColors
|
9
9
|
class << self
|
10
|
-
def base64(source,
|
11
|
-
RailsDominantColors::Base64.new(source,
|
10
|
+
def base64(source, colors = 5)
|
11
|
+
RailsDominantColors::Base64.new(source, colors)
|
12
12
|
end
|
13
13
|
|
14
|
-
def url(source,
|
15
|
-
RailsDominantColors::Url.new(source,
|
14
|
+
def url(source, colors = 5)
|
15
|
+
RailsDominantColors::Url.new(source, colors)
|
16
16
|
end
|
17
17
|
|
18
|
-
def path(source,
|
19
|
-
RailsDominantColors::Path.new(source,
|
18
|
+
def path(source, colors = 5)
|
19
|
+
RailsDominantColors::Path.new(source, colors)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -13,9 +13,9 @@ module RailsDominantColors
|
|
13
13
|
|
14
14
|
attr_reader(:source, :colors)
|
15
15
|
|
16
|
-
def initialize(source,
|
16
|
+
def initialize(source, colors)
|
17
17
|
@source = source
|
18
|
-
@colors =
|
18
|
+
@colors = colors
|
19
19
|
end
|
20
20
|
|
21
21
|
def to_hex_alpha
|
@@ -35,11 +35,24 @@ module RailsDominantColors
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def to_hsl_alpha
|
38
|
-
@to_hsl_alpha ||= sort_by_size.map
|
38
|
+
@to_hsl_alpha ||= sort_by_size.map do |x|
|
39
|
+
rgb_to_hsl(
|
40
|
+
x[:r] / 255.0,
|
41
|
+
x[:g] / 255.0,
|
42
|
+
x[:b] / 255.0,
|
43
|
+
x[:a]
|
44
|
+
)
|
45
|
+
end
|
39
46
|
end
|
40
47
|
|
41
48
|
def to_hsl
|
42
|
-
@to_hsl ||= sort_by_size.map
|
49
|
+
@to_hsl ||= sort_by_size.map do |x|
|
50
|
+
rgb_to_hsl(
|
51
|
+
x[:r] / 255.0,
|
52
|
+
x[:g] / 255.0,
|
53
|
+
x[:b] / 255.0
|
54
|
+
)
|
55
|
+
end
|
43
56
|
end
|
44
57
|
|
45
58
|
def to_pct
|
@@ -107,14 +120,8 @@ module RailsDominantColors
|
|
107
120
|
}
|
108
121
|
end
|
109
122
|
|
110
|
-
# FIXME: refactor
|
111
123
|
def rgb_to_hsl(r, g, b, a = nil)
|
112
|
-
r
|
113
|
-
g /= 255.0
|
114
|
-
b /= 255.0
|
115
|
-
|
116
|
-
max = [r, g, b].max
|
117
|
-
min = [r, g, b].min
|
124
|
+
min, max = min_max(r, g, b)
|
118
125
|
|
119
126
|
l = (max + min) / 2.0
|
120
127
|
|
@@ -131,6 +138,16 @@ module RailsDominantColors
|
|
131
138
|
h /= 6.0
|
132
139
|
end
|
133
140
|
|
141
|
+
format_hsl(h, s, l, a)
|
142
|
+
end
|
143
|
+
|
144
|
+
def min_max(r, g, b)
|
145
|
+
max = [r, g, b].max
|
146
|
+
min = [r, g, b].min
|
147
|
+
[min, max]
|
148
|
+
end
|
149
|
+
|
150
|
+
def format_hsl(h, s, l, a)
|
134
151
|
[(h * 360).round, (s * 100).round, (l * 100).round, a].compact
|
135
152
|
end
|
136
153
|
end
|
@@ -4,10 +4,10 @@ require 'base64'
|
|
4
4
|
|
5
5
|
module RailsDominantColors
|
6
6
|
class Base64 < Base
|
7
|
-
def initialize(source,
|
7
|
+
def initialize(source, colors)
|
8
8
|
raise(EmptySource) if source.nil? || source.empty?
|
9
9
|
|
10
|
-
super(process(source),
|
10
|
+
super(process(source), colors)
|
11
11
|
end
|
12
12
|
|
13
13
|
private
|
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
module RailsDominantColors
|
4
4
|
class Path < Base
|
5
|
-
def initialize(source,
|
5
|
+
def initialize(source, colors)
|
6
6
|
raise(EmptySource) if source.nil? || source.empty?
|
7
7
|
raise(FileNotFound) unless file_exist?(source)
|
8
8
|
raise(NotAnImage) unless file_is_image?(source)
|
9
9
|
|
10
|
-
super(source,
|
10
|
+
super(source, colors)
|
11
11
|
end
|
12
12
|
|
13
13
|
private
|
@@ -4,10 +4,10 @@ require 'net/http'
|
|
4
4
|
|
5
5
|
module RailsDominantColors
|
6
6
|
class Url < Base
|
7
|
-
def initialize(source,
|
7
|
+
def initialize(source, colors)
|
8
8
|
raise(EmptySource) if source.nil? || source.empty?
|
9
9
|
|
10
|
-
super(process(source),
|
10
|
+
super(process(source), colors)
|
11
11
|
end
|
12
12
|
|
13
13
|
def process(source)
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.summary = 'Extract the dominant color(s) from an image'
|
12
12
|
spec.description = <<~TEXT
|
13
13
|
Extract the dominant color(s) from an image (remote image, locally image, base64 image etc...)
|
14
|
-
|
14
|
+
Get HEX(A) color(s), RGB(A) color(s), HSL(A) color(s)
|
15
15
|
TEXT
|
16
16
|
|
17
17
|
spec.homepage = 'https://github.com/OpenGems/rails_dominant_colors'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_dominant_colors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boris BRESCIANI
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05
|
11
|
+
date: 2020-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -96,13 +96,14 @@ dependencies:
|
|
96
96
|
version: '4.10'
|
97
97
|
description: |
|
98
98
|
Extract the dominant color(s) from an image (remote image, locally image, base64 image etc...)
|
99
|
-
|
99
|
+
Get HEX(A) color(s), RGB(A) color(s), HSL(A) color(s)
|
100
100
|
email:
|
101
101
|
- boris2bresciani@gmail.com
|
102
102
|
executables: []
|
103
103
|
extensions: []
|
104
104
|
extra_rdoc_files: []
|
105
105
|
files:
|
106
|
+
- ".coveralls.yml"
|
106
107
|
- ".gitignore"
|
107
108
|
- ".rspec"
|
108
109
|
- ".rubocop.yml"
|
@@ -127,7 +128,7 @@ licenses:
|
|
127
128
|
metadata:
|
128
129
|
homepage_uri: https://github.com/OpenGems/rails_dominant_colors
|
129
130
|
source_code_uri: https://github.com/OpenGems/rails_dominant_colors
|
130
|
-
post_install_message:
|
131
|
+
post_install_message:
|
131
132
|
rdoc_options: []
|
132
133
|
require_paths:
|
133
134
|
- lib
|
@@ -143,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
144
|
version: '0'
|
144
145
|
requirements: []
|
145
146
|
rubygems_version: 3.1.2
|
146
|
-
signing_key:
|
147
|
+
signing_key:
|
147
148
|
specification_version: 4
|
148
149
|
summary: Extract the dominant color(s) from an image
|
149
150
|
test_files: []
|