carrierwave-color 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/README.md +2 -1
- data/lib/carrierwave/color/detection.rb +5 -4
- data/lib/carrierwave/color/version.rb +1 -1
- data/spec/detection_spec.rb +11 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b6fc42d5e7ce84c7e1c44872f3a3342980435cd
|
4
|
+
data.tar.gz: f8ce682015304674dde3184d29467444f27df637
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 583b69fa74bc3c3d66c805d532d160f011fefabf73e2aca5887bcfc3f1b11e470a1c5d9911d1c06a36ef70f01ec9cb33b24da13c2254c231a008148c21f74d05
|
7
|
+
data.tar.gz: b4f5a905ae31fbc9ff50b3ca86fd8d9cf55738e37f389f156c9b65d6937fb8ad7225603dfe104386d27e15fdcd4a0e8e6490e3cea99aa94631d3c482aa8b563e
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.1
|
data/README.md
CHANGED
@@ -10,9 +10,10 @@ or to index images for a "search by color" feature.
|
|
10
10
|
Installation
|
11
11
|
------------
|
12
12
|
|
13
|
-
Add
|
13
|
+
Add the following lines to your application's Gemfile:
|
14
14
|
|
15
15
|
```ruby
|
16
|
+
# Detect the dominant color of images on upload
|
16
17
|
gem "carrierwave-color"
|
17
18
|
```
|
18
19
|
|
@@ -12,13 +12,14 @@ module CarrierWave
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def dominant_from_palette_html(path, palette_hexes)
|
15
|
-
|
15
|
+
scores = Colorscore::Histogram.new(path).scores
|
16
16
|
palette = Colorscore::Palette.from_hex(palette_hexes)
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
# Return nil values from scores
|
19
|
+
scores.reject! { |_color_score, color| color.nil? }
|
20
|
+
return nil if scores.empty?
|
20
21
|
|
21
|
-
scores = palette.scores(
|
22
|
+
scores = palette.scores(scores, 1)
|
22
23
|
_score, color = scores.first
|
23
24
|
color.html
|
24
25
|
end
|
data/spec/detection_spec.rb
CHANGED
@@ -4,6 +4,7 @@ module CarrierWave
|
|
4
4
|
module Color
|
5
5
|
RSpec.describe Detection do
|
6
6
|
let(:path) { File.expand_path('../fixtures/red-rainbow.jpg', __FILE__) }
|
7
|
+
let(:blue_color) { ::Color::RGB.from_html("0066cc") }
|
7
8
|
|
8
9
|
describe ".dominant_html" do
|
9
10
|
it "returns the correct hex code" do
|
@@ -20,12 +21,21 @@ module CarrierWave
|
|
20
21
|
|
21
22
|
it "returns nil when the histogram fails" do
|
22
23
|
allow_any_instance_of(Colorscore::Histogram).to receive(:scores)
|
23
|
-
.and_return([[1, nil]])
|
24
|
+
.and_return([[1, nil], [1, nil]])
|
24
25
|
|
25
26
|
palette = %w(ff0000 00ff00 0000ff)
|
26
27
|
result = Detection.dominant_from_palette_html(path, palette)
|
27
28
|
expect(result).to be_nil
|
28
29
|
end
|
30
|
+
|
31
|
+
it "returns the only color found if the histogram contains any color" do
|
32
|
+
allow_any_instance_of(Colorscore::Histogram).to receive(:scores)
|
33
|
+
.and_return([[1, blue_color], [1, nil]])
|
34
|
+
|
35
|
+
palette = %w(ff0000 00ff00 0000ff)
|
36
|
+
result = Detection.dominant_from_palette_html(path, palette)
|
37
|
+
expect(result).to eq("#0000ff")
|
38
|
+
end
|
29
39
|
end
|
30
40
|
end
|
31
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave-color
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sunny Ripert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorscore
|
@@ -75,6 +75,7 @@ extensions: []
|
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
77
|
- ".gitignore"
|
78
|
+
- ".ruby-version"
|
78
79
|
- Gemfile
|
79
80
|
- README.md
|
80
81
|
- Rakefile
|
@@ -106,9 +107,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
107
|
version: '0'
|
107
108
|
requirements: []
|
108
109
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.5.1
|
110
111
|
signing_key:
|
111
112
|
specification_version: 4
|
112
113
|
summary: Store the dominant color of an image with CarrierWave
|
113
114
|
test_files: []
|
114
|
-
has_rdoc:
|