shrine-color 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a7d2d6bf761232e62fdc34b0e1378dfa8288aab5
4
- data.tar.gz: a15371b69e211694cb0c642bf95ef8664c2d482a
2
+ SHA256:
3
+ metadata.gz: 2023aa78c934dff3cc608b6ee525b79ec8e2a2ab34b0eb10c9714cb59155b358
4
+ data.tar.gz: 1af9151c8c4f44fcb06eee37583ea68490ec47096ae4fc8d74f35ec5a4daba00
5
5
  SHA512:
6
- metadata.gz: cd31b407cef673b5c6b454bbdb404c70aaec79433ed7f1b34a08e826a344f819daf53836675c49bf81c5d7a82cb9c4a43d4e23d39bbed82d9d6b60a53aabccd0
7
- data.tar.gz: 8836c647e54b2bc93e4cab88e30b6e524bdabdb623abbf9d986990183464deaae60cdcf625406c4fa9173b0d63b5f0ec028c91c469836df8d0c00d63d0e19cfa
6
+ metadata.gz: fffa4367e60af3be0ef9c67b4b08acbe9fa2571498f664931e7a43ee36f878175527819ebd4566c479c07ca96aa0ff04cc8e393d3ab8d144984776dc34c03618
7
+ data.tar.gz: bbebd1fe938f8bf4a53b447989c1403bfb49423eaa0ba7692f5cef29fdfed5aab86a3377e135e9e5dd35cbecdada9048def46fa5f007378648ca14f9fac1732a
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.5
4
+ - 2.4
5
+ - 2.3
6
+ before_script:
7
+ - convert -version
data/Gemfile.lock CHANGED
@@ -1,17 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shrine-color (0.1)
5
- jnylen-colorscore (>= 0.1.1)
6
- shrine (>= 2.0)
4
+ shrine-color (0.3.0)
5
+ jnylen-colorscore (~> 0.1, >= 0.1.3)
6
+ shrine (~> 2.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
11
  color (1.8)
12
12
  diff-lcs (1.2.5)
13
- down (2.3.6)
14
- jnylen-colorscore (0.1.1)
13
+ down (4.5.0)
14
+ jnylen-colorscore (0.1.3)
15
15
  color
16
16
  rake (11.2.2)
17
17
  rspec (3.5.0)
@@ -27,8 +27,8 @@ GEM
27
27
  diff-lcs (>= 1.2.0, < 2.0)
28
28
  rspec-support (~> 3.5.0)
29
29
  rspec-support (3.5.0)
30
- shrine (2.2.0)
31
- down (>= 2.3.5)
30
+ shrine (2.11.0)
31
+ down (~> 4.1)
32
32
 
33
33
  PLATFORMS
34
34
  ruby
@@ -40,4 +40,4 @@ DEPENDENCIES
40
40
  shrine-color!
41
41
 
42
42
  BUNDLED WITH
43
- 1.12.5
43
+ 1.16.2
data/README.md CHANGED
@@ -5,6 +5,8 @@ Get the dominant color of an image using colorscore (updated version by me). Thi
5
5
 
6
6
  This is based on carrierwave-color by Sunny Ripert (sunny).
7
7
 
8
+ NOTE: The palettes/dominiant_color grabbed from images may differ between imagemagick versions.
9
+
8
10
  Requirements
9
11
  ------------
10
12
 
@@ -43,10 +45,10 @@ class ImageUploader < Shrine
43
45
  dominant_color(io.path)
44
46
  end
45
47
 
46
- # palette color with version and own array of colors.
48
+ # palette color with version, color count and own array of colors.
47
49
  add_metadata :palette_color do |io, context|
48
50
  if context[:version] == :small
49
- palette_color(io.path, ['ff0000', '00ff00', '0000ff'])
51
+ palette_color(io.path, 3, ['ff0000', '00ff00', '0000ff'])
50
52
  end
51
53
  end
52
54
  end
@@ -23,7 +23,7 @@ class Shrine
23
23
  end
24
24
 
25
25
  # Matches the dominant color to the closest color in the array provided
26
- def palette_color(io_path, palette_hexes = DEFAULT_PALETTE_HEXES)
26
+ def palette_color(io_path, color_count = 1, palette_hexes = DEFAULT_PALETTE_HEXES)
27
27
  histogram = Colorscore::Histogram.new(io_path)
28
28
  palette = Colorscore::Palette.from_hex(palette_hexes)
29
29
 
@@ -31,8 +31,7 @@ class Shrine
31
31
  return nil if histogram_scores.first.last.nil?
32
32
 
33
33
  scores = palette.scores(histogram_scores, 1)
34
- _score, color = scores.first
35
- color.html
34
+ scores.first(color_count).map { |_score, color| color.html}
36
35
  end
37
36
 
38
37
  end
data/shrine-color.gemspec CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "shrine-color"
6
- spec.version = "0.2.0"
6
+ spec.version = "0.3.0"
7
7
  spec.authors = ["Joakim Nylen"]
8
8
  spec.email = ["me@jnylen.nu"]
9
9
  spec.summary = "Return the dominant color of an image in Shrine."
@@ -14,8 +14,8 @@ Gem::Specification.new do |spec|
14
14
  spec.files = `git ls-files -z`.split("\x0")
15
15
  spec.require_paths = ["lib"]
16
16
 
17
- spec.add_dependency "shrine", ">= 2.0"
18
- spec.add_dependency "jnylen-colorscore", ">= 0.1.2"
17
+ spec.add_dependency "shrine", "~> 2.0"
18
+ spec.add_dependency "jnylen-colorscore", "~> 0.1", ">= 0.1.3"
19
19
 
20
20
  spec.add_development_dependency "bundler", "~> 1.12"
21
21
  spec.add_development_dependency "rake", "~> 11.1"
@@ -2,14 +2,17 @@ require 'spec_helper'
2
2
 
3
3
  describe Shrine::Plugins::Color do
4
4
  before do
5
- @uploader = uploader { plugin :color }
5
+ @uploader = uploader {
6
+ plugin :determine_mime_type
7
+ plugin :color
8
+ }
6
9
  end
7
10
 
8
11
  describe ":dominant_color" do
9
12
  it "extracts dominant_color from files via add_metadata" do
10
13
  @uploader.class.add_metadata(:dominant_color) { |io, context| dominant_color(io.path) }
11
14
  uploaded_file = @uploader.upload(File.open("spec/fixtures/bora.jpg"))
12
- expect(uploaded_file.metadata.fetch("dominant_color")).to eq("#48839f")
15
+ expect(uploaded_file.metadata.fetch("dominant_color")).to eq("#5c97a7")
13
16
  end
14
17
  end
15
18
 
@@ -17,13 +20,25 @@ describe Shrine::Plugins::Color do
17
20
  it "extracts palette_color from files with default hexes via add_metadata" do
18
21
  @uploader.class.add_metadata(:palette_color) { |io, context| palette_color(io.path) }
19
22
  uploaded_file = @uploader.upload(File.open("spec/fixtures/bora.jpg"))
20
- expect(uploaded_file.metadata.fetch("palette_color")).to eq("#333399")
23
+ expect(uploaded_file.metadata.fetch("palette_color")).to eq(["#333399"])
21
24
  end
22
25
 
23
26
  it "extracts palette_color from files with custom hexes via add_metadata" do
24
- @uploader.class.add_metadata(:palette_color) { |io, context| palette_color(io.path, ['ff0000', '00ff00', '0000ff']) }
27
+ @uploader.class.add_metadata(:palette_color) { |io, context| palette_color(io.path, 1, ['ff0000', '00ff00', '0000ff']) }
25
28
  uploaded_file = @uploader.upload(File.open("spec/fixtures/bora.jpg"))
26
- expect(uploaded_file.metadata.fetch("palette_color")).to eq("#0000ff")
29
+ expect(uploaded_file.metadata.fetch("palette_color")).to eq(["#0000ff"])
30
+ end
31
+
32
+ it "extracts 3 palette_colors from files with default hexes via add_metadata" do
33
+ @uploader.class.add_metadata(:palette_color) { |io, context| palette_color(io.path, 3) }
34
+ uploaded_file = @uploader.upload(File.open("spec/fixtures/bora.jpg"))
35
+ expect(uploaded_file.metadata.fetch("palette_color")).to eq(["#333399", "#0066cc", "#66cccc"])
36
+ end
37
+
38
+ it "extracts 3 palette_colors from files with custom hexes via add_metadata" do
39
+ @uploader.class.add_metadata(:palette_color) { |io, context| palette_color(io.path, 3, ['ff0000', '00ff00', '0000ff']) }
40
+ uploaded_file = @uploader.upload(File.open("spec/fixtures/bora.jpg"))
41
+ expect(uploaded_file.metadata.fetch("palette_color")).to eq(["#0000ff", "#00ff00"])
27
42
  end
28
43
  end
29
44
 
metadata CHANGED
@@ -1,43 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shrine-color
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joakim Nylen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-11 00:00:00.000000000 Z
11
+ date: 2018-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shrine
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: jnylen-colorscore
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
31
34
  - - ">="
32
35
  - !ruby/object:Gem::Version
33
- version: 0.1.2
36
+ version: 0.1.3
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '0.1'
38
44
  - - ">="
39
45
  - !ruby/object:Gem::Version
40
- version: 0.1.2
46
+ version: 0.1.3
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: bundler
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -88,6 +94,7 @@ extensions: []
88
94
  extra_rdoc_files: []
89
95
  files:
90
96
  - ".gitignore"
97
+ - ".travis.yml"
91
98
  - Gemfile
92
99
  - Gemfile.lock
93
100
  - LICENSE
@@ -118,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
125
  version: '0'
119
126
  requirements: []
120
127
  rubyforge_project:
121
- rubygems_version: 2.5.1
128
+ rubygems_version: 2.7.7
122
129
  signing_key:
123
130
  specification_version: 4
124
131
  summary: Return the dominant color of an image in Shrine.