rails_dominant_colors 0.1.0 → 0.1.1

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: b3d29a8561ce7e4e3be8d53818c5957f1508f04ff890b4faa8c8b9c0753e5c5f
4
- data.tar.gz: 7c4fb0ba739696b70076aacd6c9f00253bfdcb675a018da183aaac762228ae4b
3
+ metadata.gz: 6dc435fa3314d1b0df479d658636dce27686304d49d776341d64d718477278d0
4
+ data.tar.gz: a0583a990a5b642156d1bf212437aa5eaf46f6f0c3d16b141d466ed748029fa2
5
5
  SHA512:
6
- metadata.gz: 7320c72aa7112c3a1b4fda7da76f9fb5fd639155b3647b4b9ce7c5e9b4d2fd826da19cae61ffbb1bfcac2e3582a5bbe0c361b38a0cd5988061101392c5db6f76
7
- data.tar.gz: f189a796a45c4f8653ec625e935fa7b78ec0d0e0536de81c6b5264a9ca3e754ec4725f1d0451699000b47302e74477b697ea2354a4e6b6e1e885986e3a3ccb44
6
+ metadata.gz: 16cbe4f16b463d0198d988084ae8c9c77a73b1c8fb0dc094ec22abb0869849cc56f841764090a41c40a3a62c7e96822b1087f719a5b73775816e006db8a0afd1
7
+ data.tar.gz: db00b0c13abd82337685d680527c25e299e8d807d7234559ec82ede75c5579a3b4a22559a14c54e8f8837d61043737104aa368318dee8b136645c7595c98120f
@@ -0,0 +1,2 @@
1
+ service_name: travis-pro
2
+ repo_token: ZNtqKdszxNXImMHT3tBJ3jI0UY8k7kJ6y
@@ -8,13 +8,13 @@ Layout/EmptyLineAfterGuardClause:
8
8
  Layout/EmptyLinesAroundBlockBody:
9
9
  Enabled: false
10
10
  Metrics/MethodLength:
11
- Max: 20
11
+ Max: 25
12
12
  Metrics/BlockLength:
13
13
  Max: 30
14
14
  Metrics/AbcSize:
15
- Max: 20
15
+ Max: 25
16
16
  Metrics/CyclomaticComplexity:
17
- Max: 20
17
+ Max: 25
18
18
  Style/RegexpLiteral:
19
19
  EnforcedStyle: percent_r
20
20
  Naming/MethodParameterName:
@@ -1,6 +1,12 @@
1
1
  ---
2
+ os: linux
2
3
  language: ruby
3
4
  cache: bundler
4
5
  rvm:
5
- - 2.7.1
6
- before_install: gem install bundler -v 2.1.4
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_dominant_colors (0.1.0)
4
+ rails_dominant_colors (0.1.1)
5
5
  mini_magick (~> 4.10)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,16 +1,15 @@
1
1
  # RailsDominantColors
2
2
 
3
-
4
3
  [![Gem Version](https://badge.fury.io/rb/rails_dominant_colors.svg)](https://badge.fury.io/rb/rails_dominant_colors)
5
- [![Maintainability](https://api.codeclimate.com/v1/badges/79cdc15c16da15562c25/maintainability)](https://codeclimate.com/github/OpenGems/rails_dominant_colors/maintainability)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/83326d81b9112b45768f/maintainability)](https://codeclimate.com/github/OpenGems/rails_dominant_colors/maintainability)
6
5
  [![Build Status](https://travis-ci.org/OpenGems/rails_dominant_colors.svg?branch=master)](https://travis-ci.org/OpenGems/rails_dominant_colors)
7
6
  [![security](https://hakiri.io/github/OpenGems/rails_dominant_colors/master.svg)](https://hakiri.io/github/OpenGems/rails_dominant_colors/master)
8
7
  ![Gem](https://img.shields.io/gem/dt/rails_dominant_colors)
9
8
  [![Coverage Status](https://coveralls.io/repos/github/OpenGems/rails_dominant_colors/badge.svg?branch=master)](https://coveralls.io/github/OpenGems/rails_dominant_colors?branch=master)
10
9
 
11
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rails_dominant_colors`. To experiment with that code, run `bin/console` for an interactive prompt.
10
+ A Ruby gem for extract the dominant color(s) from an image (remote image, locally image, base64 image etc...)
12
11
 
13
- TODO: Delete this and the text above, and describe your gem
12
+ Get HEX(A) colors, RGB(A) colors and HSL(a) colors
14
13
 
15
14
  ## Installation
16
15
 
@@ -30,18 +29,41 @@ Or install it yourself as:
30
29
 
31
30
  ## Usage
32
31
 
33
- TODO: Write usage instructions here
32
+ ```ruby
33
+ opts = {
34
+ colors: 5 # Number of colors (default: 5)
35
+ }
36
+
37
+ colors = RailsDominantColors::Base64.new('data:image/png;base64,awesome-image', opts)
34
38
 
35
- ## Development
39
+ # or
36
40
 
37
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
+ RailsDominantColors::Url.new('https://awesome-url.com/awesome-image.png')
38
42
 
39
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
43
+ # or
40
44
 
41
- ## Contributing
45
+ RailsDominantColors::Path.new('/awesome/path/awesome-image.png')
46
+
47
+ # and
48
+
49
+ colors.to_hex # => ["#FF007F", "#000000", "#1C000F", "#A0004F", "#000000"]
50
+ colors.to_hex_alpha # => ["#FF007FFF", "#00000000", "#1C000FFE", "#A0004FFF", "#0000005F"]
51
+
52
+ colors.to_rgb # => [[255, 0, 127], [0, 0, 0], [28, 0, 15], [160, 0, 79], [0, 0, 0]]
53
+ 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
54
 
43
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rails_dominant_colors.
55
+ colors.to_hsl # => [[330, 100, 50], [0, 0, 0], [328, 100, 5], [330, 100, 31], [0, 0, 0]]
56
+ 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]]
57
+
58
+ # Awesome bonus
59
+ colors.to_pct # => [52.16, 37.45, 9.93, 0.35, 0.1]
60
+
61
+ ```
62
+
63
+
64
+ ## Contributing
44
65
 
66
+ 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
67
 
46
68
  ## License
47
69
 
@@ -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 { |x| rgb_to_hsl(x[:r], x[:g], x[:b], x[:a]) }
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 { |x| rgb_to_hsl(x[:r], x[:g], x[:b]) }
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 /= 255.0
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsDominantColors
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
@@ -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
- Convert to HEX(A), RGB(A), HSL(a)'
14
+ Convert to HEX(A), RGB(A), HSL(a)
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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boris BRESCIANI
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-02 00:00:00.000000000 Z
11
+ date: 2020-05-03 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
- Convert to HEX(A), RGB(A), HSL(a)'
99
+ Convert to HEX(A), RGB(A), HSL(a)
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"