color_converters 0.1.4 → 0.1.5

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: b9dbc30347819cfe3042c01530a7b28458f16286ca4267537148a86a918a684a
4
- data.tar.gz: c8ce7ec66163f244f6714510acc883c8904275bea0ce0fada6bdcc364350b64a
3
+ metadata.gz: bebeb93877646ae484c2432784d6acb4b5a14437024adf5fb4e044f83ccc7de8
4
+ data.tar.gz: 98c736ac93f9ecbad9a989f0dc53f9a4bc7c6cf699f9cf6f891cfd7df954483a
5
5
  SHA512:
6
- metadata.gz: 87e552e208529b594de4302d56c645217b6cfad12018b58b12e6fc57bc3bef86170139c9c63d2268ef88f05953203b175950b20c7a3bb6decf69823926a8a8e3
7
- data.tar.gz: 79cd6ad185469e763f30c5cede6d3de05c1b1ec5406c44e88b1bf9caae181480b2617e32108807e548a224f3661d9c769d1e98b16377bba36c4a3093534e1ec9
6
+ metadata.gz: 44b8fa514afa086c085af17f0d112b2e575d77ec44dba6cedb5d6d2c98987c0da3e0db74a06e72e2f708f8ffd16f258a54a8a79effd2692b1675dfd041975be0
7
+ data.tar.gz: 1b2a7a03dc0e7aec402e5a289ba692d83ba9d475cdda0e34f6d718abc141c8135dcf49f7b376ab7851e647b6c4f10a69fc7683f5d66a7b3af2ffa7d0c166ee00
data/README.md CHANGED
@@ -1,190 +1,199 @@
1
- # Color Converters
2
-
3
- > Give me a colour and I'll convert it.
4
-
5
- Color Converters is an ruby gem package for use in ruby or other projects that provides conversions for colours to other colour spaces.
6
- Given a colour in [Hexadecimal, RGA(A), HSL(A), HSV, HSB, CMYK, XYZ, CIELAB, or OKLCH format](https://github.com/devrieda/color_conversion), it can convert the colour to those other spaces.
7
-
8
- > Lab and LCH colour spaces are special in that the perceived difference between two colours is proportional to their Euclidean distance in colour space. This special property, called perceptual uniformity, makes them ideal for accurate visual encoding of data. In contrast, the more familiar RGB and HSL colour spaces distort data when used for visualization.
9
-
10
- ## Converters
11
-
12
- Colours can be converted between the following spaces:
13
-
14
- - hex
15
- - rgb(a)
16
- - hsl(a)
17
- - hsv/hsb
18
- - cmyk
19
- - xyz
20
- - cielab
21
- - cielch
22
- - oklab (not always reliable when going from oklab to the source colour)
23
- - oklch (not always reliable when going from oklch to the source colour)
24
- - name
25
-
26
- ## Installation
27
-
28
- Install the gem and add to the application's Gemfile by executing:
29
-
30
- ```bash
31
- bundle add color_converters
32
- ```
33
-
34
- If bundler is not being used to manage dependencies, install the gem by executing:
35
-
36
- ```bash
37
- gem install color_converters
38
- ```
39
-
40
- ## Usage
41
-
42
- Initialize a colour:
43
-
44
- ```ruby
45
- # from hex
46
- colour = ColorConverters::Color.new("#3366cc")
47
- colour = ColorConverters::Color.new("#36c")
48
-
49
- # from rgb(a)
50
- colour = ColorConverters::Color.new(r: 51, g: 102, b: 204)
51
- colour = ColorConverters::Color.new(r: 51, g: 102, b: 204, a: 0.5)
52
-
53
- # from hsl(a)
54
- colour = ColorConverters::Color.new(h: 225, s: 73, l: 57)
55
- colour = ColorConverters::Color.new(h: 225, s: 73, l: 57, a: 0.5)
56
-
57
- # from hsv/hsb
58
- colour = ColorConverters::Color.new(h: 220, s: 75, v: 80)
59
- colour = ColorConverters::Color.new(h: 220, s: 75, b: 80)
60
-
61
- # from cmyk
62
- colour = ColorConverters::Color.new(c: 74, m: 58, y: 22, k: 3)
63
-
64
- # from xyz
65
- colour = ColorConverters::Color.new(x: 16, y: 44, z: 32)
66
-
67
- # from cielab
68
- colour = ColorConverters::Color.new(l: 16, a: 44, b: 32, space: :cie)
69
-
70
- # from cielch
71
- colour = ColorConverters::Color.new(l: 16, c: 44, h: 32, space: :cie)
72
-
73
- # from oklab
74
- colour = ColorConverters::Color.new(l: 16, a: 44, b: 32, space: :ok)
75
-
76
- # from oklch
77
- colour = ColorConverters::Color.new(l: 16, c: 44, h: 32, space: :ok)
78
-
79
- # from textual colour
80
- colour = ColorConverters::Color.new("blue")
81
-
82
- # from a css rgb(a) string
83
- colour = ColorConverters::Color.new("rgb(51, 102, 204)")
84
- colour = ColorConverters::Color.new("rgba(51, 102, 204, 0.5)")
85
-
86
- # from a css hsl(a) string
87
- colour = ColorConverters::Color.new("hsl(225, 73%, 57%)")
88
- colour = ColorConverters::Color.new("hsl(225, 73%, 57%, 0.5)")
89
- ```
90
-
91
- Converters
92
-
93
- ```ruby
94
- colour = ColorConverters::Color.new(r: 70, g: 130, b: 180, a: 0.5)
95
-
96
- colour.alpha
97
- => 0.5
98
-
99
- colour.rgb
100
- => {:r=>70, :g=>130, :b=>180}
101
-
102
- colour.hsl
103
- => {:h=>207, :s=>44, :l=>49}
104
-
105
- colour.hsv
106
- => {:h=>207, :s=>61, :v=>71}
107
-
108
- colour.hsb
109
- => {:h=>207, :s=>61, :b=>71}
110
-
111
- colour.cmyk
112
- => {:c=>61, :m=>28, :y=>0, :k=>29}
113
-
114
- colour.xyz
115
- => {:x=>33, :y=>21, :z=>54}
116
-
117
- colour.cielab
118
- => {:l=>52.47, :a=>-4.08, :b=>-32.19}
119
-
120
- colour.cielch
121
- => {:l=>52.47, :c=>32.45, :h=>262.78}
122
-
123
- colour.oklab # not always accurate
124
- => {:l=>52.47, :a=>-4.08, :b=>-32.19}
125
-
126
- colour.oklch # not always accurate
127
- => {:l=>52.47, :c=>32.45, :h=>262.78}
128
-
129
- colour.hex
130
- => "#4682b4"
131
-
132
- colour.name
133
- => "steelblue"
134
- ```
135
-
136
- ## Options
137
-
138
- ### space
139
-
140
- As there are certain colour spaces that use the same letter keys, there needed to be a way to different between those space.
141
- The space parameter allows that, with examples in the usage code above
142
-
143
- ```ruby
144
- ColorConverters::Color.new(l: 64, a: 28, b: -15, space: :cie)
145
- ColorConverters::Color.new(l: 64, a: 28, b: -15, space: :ok)
146
- ```
147
-
148
- ### limit_override
149
-
150
- By default all values are checked to be within the expected number ranges, i.e.; rgb between 0-255 each.
151
- This parameter allows you to ignore those ranges and submit any values you want.
152
-
153
- ```ruby
154
- ColorConverters::Color.new(r: 270, g: 1300, b: 380, a: 0.5, limit_override: true)
155
- ```
156
-
157
- ### fuzzy
158
-
159
- Name conversions by default look for exact matches between the hex value of the colour
160
-
161
- ```ruby
162
- colour = ColorConverters::Color.new(r: 175.8, g: 196.4, b: 222.1)
163
-
164
- colour.name
165
- => nil
166
-
167
- colour.name(fuzzy: true)
168
- => 'lightsteelblue'
169
- ```
170
-
171
- ## Development
172
-
173
- [Converting Colors](https://convertingcolors.com/) and [Colorffy](https://colorffy.com/) can be used to help verify results. Different calculators use different exponents and standards so there can be discrepency across them (like this calculator for LCH).
174
-
175
- 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.
176
-
177
- 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
178
-
179
- ## Contributing
180
-
181
- Bug reports and pull requests are welcome on GitHub at <https://github.com/louiswdavis/color_converters>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/louiswdavis/color_converters/blob/master/CODE_OF_CONDUCT.md).
182
-
183
- ## License
184
-
185
- Forked from original gem by Derek DeVries.
186
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
187
-
188
- ## Code of Conduct
189
-
190
- Everyone interacting in the ColorConverters project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/louiswdavis/color_converters/blob/master/CODE_OF_CONDUCT.md).
1
+ # Color Converters
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/color_converters.svg)](https://badge.fury.io/rb/color_converters)
4
+ ![Static Badge](https://img.shields.io/badge/RubyGems-red?link=https%3A%2F%2Frubygems.org%2Fgems%color_converters)
5
+
6
+ > Give me a colour and I'll convert it.
7
+
8
+ Color Converters is an ruby gem package for use in ruby or other projects that provides conversions for colours to other colour spaces.
9
+ Given a colour in [Hexadecimal, RGA(A), HSL(A), HSV, HSB, CMYK, XYZ, CIELAB, or OKLCH format](https://github.com/devrieda/color_conversion), it can convert the colour to those other spaces.
10
+
11
+ > Lab and LCH colour spaces are special in that the perceived difference between two colours is proportional to their Euclidean distance in colour space. This special property, called perceptual uniformity, makes them ideal for accurate visual encoding of data. In contrast, the more familiar RGB and HSL colour spaces distort data when used for visualization.
12
+
13
+ ## Converters
14
+
15
+ Colours can be converted between the following spaces:
16
+
17
+ - hex
18
+ - rgb(a)
19
+ - hsl(a)
20
+ - hsv/hsb
21
+ - cmyk
22
+ - xyz
23
+ - cielab
24
+ - cielch
25
+ - oklab (not always reliable when going from oklab to the source colour)
26
+ - oklch (not always reliable when going from oklch to the source colour)
27
+ - name
28
+
29
+ ## Installation
30
+
31
+ Install the gem and add to the application's Gemfile by executing:
32
+
33
+ ```bash
34
+ bundle add color_converters
35
+ ```
36
+
37
+ If bundler is not being used to manage dependencies, install the gem by executing:
38
+
39
+ ```bash
40
+ gem install color_converters
41
+ ```
42
+
43
+ ## Usage
44
+
45
+ Initialize a colour:
46
+
47
+ ```ruby
48
+ # from hex
49
+ colour = ColorConverters::Color.new("#3366cc")
50
+ colour = ColorConverters::Color.new("#36c")
51
+
52
+ # from rgb(a)
53
+ colour = ColorConverters::Color.new(r: 51, g: 102, b: 204)
54
+ colour = ColorConverters::Color.new(r: 51, g: 102, b: 204, a: 0.5)
55
+
56
+ # from hsl(a)
57
+ colour = ColorConverters::Color.new(h: 225, s: 73, l: 57)
58
+ colour = ColorConverters::Color.new(h: 225, s: 73, l: 57, a: 0.5)
59
+
60
+ # from hsv/hsb
61
+ colour = ColorConverters::Color.new(h: 220, s: 75, v: 80)
62
+ colour = ColorConverters::Color.new(h: 220, s: 75, b: 80)
63
+
64
+ # from cmyk
65
+ colour = ColorConverters::Color.new(c: 74, m: 58, y: 22, k: 3)
66
+
67
+ # from xyz
68
+ colour = ColorConverters::Color.new(x: 16, y: 44, z: 32)
69
+
70
+ # from cielab
71
+ colour = ColorConverters::Color.new(l: 16, a: 44, b: 32, space: :cie)
72
+
73
+ # from cielch
74
+ colour = ColorConverters::Color.new(l: 16, c: 44, h: 32, space: :cie)
75
+
76
+ # from oklab
77
+ colour = ColorConverters::Color.new(l: 16, a: 44, b: 32, space: :ok)
78
+
79
+ # from oklch
80
+ colour = ColorConverters::Color.new(l: 16, c: 44, h: 32, space: :ok)
81
+
82
+ # from textual colour
83
+ colour = ColorConverters::Color.new("blue")
84
+
85
+ # from a css rgb(a) string
86
+ colour = ColorConverters::Color.new("rgb(51, 102, 204)")
87
+ colour = ColorConverters::Color.new("rgba(51, 102, 204, 0.5)")
88
+
89
+ # from a css hsl(a) string
90
+ colour = ColorConverters::Color.new("hsl(225, 73%, 57%)")
91
+ colour = ColorConverters::Color.new("hsl(225, 73%, 57%, 0.5)")
92
+ ```
93
+
94
+ Converters
95
+
96
+ ```ruby
97
+ colour = ColorConverters::Color.new("rgba(70, 130, 180, 0.5)")
98
+ colour = ColorConverters::Color.new(r: 70, g: 130, b: 180, a: 0.5)
99
+
100
+ colour.alpha
101
+ => 0.5
102
+
103
+ colour.rgb
104
+ => {:r=>70, :g=>130, :b=>180}
105
+
106
+ colour.hsl
107
+ => {:h=>207, :s=>44, :l=>49}
108
+
109
+ colour.hsv
110
+ => {:h=>207, :s=>61, :v=>71}
111
+
112
+ colour.hsb
113
+ => {:h=>207, :s=>61, :b=>71}
114
+
115
+ colour.cmyk
116
+ => {:c=>61, :m=>28, :y=>0, :k=>29}
117
+
118
+ colour.xyz
119
+ => {:x=>33, :y=>21, :z=>54}
120
+
121
+ colour.cielab
122
+ => {:l=>52.47, :a=>-4.08, :b=>-32.19}
123
+
124
+ colour.cielch
125
+ => {:l=>52.47, :c=>32.45, :h=>262.78}
126
+
127
+ colour.oklab # not always accurate
128
+ => {:l=>52.47, :a=>-4.08, :b=>-32.19}
129
+
130
+ colour.oklch # not always accurate
131
+ => {:l=>52.47, :c=>32.45, :h=>262.78}
132
+
133
+ colour.hex
134
+ => "#4682b4"
135
+
136
+ colour.name
137
+ => "steelblue"
138
+ ```
139
+
140
+ ## Options
141
+
142
+ ### space
143
+
144
+ As there are certain colour spaces that use the same letter keys, there needed to be a way to different between those space.
145
+ The space parameter allows that, with examples in the usage code above
146
+
147
+ ```ruby
148
+ ColorConverters::Color.new(l: 64, a: 28, b: -15, space: :cie)
149
+ ColorConverters::Color.new(l: 64, a: 0.28, b: -0.15, space: :ok)
150
+ ```
151
+
152
+ ### limit_override
153
+
154
+ By default all values are checked to be within the expected number ranges, i.e.; rgb between 0-255 each but there are certain spaces where this is less fixed which this option is purposed for.
155
+ This parameter allows you to ignore those ranges and submit any values you want.
156
+ **WARNING: even if you use this, there may be certain conversions that can not handle the large source values; e.g.**
157
+
158
+ ```ruby
159
+ ColorConverters::Color.new(r: 270, g: 1300, b: 380, a: 0.5, limit_override: true).rgb
160
+ => {r: 270.0, g: 1300.0, b: 380.0}
161
+
162
+ ColorConverters::Color.new(x: 174, y: 135, z: 137, limit_override: true).xyz
163
+ => {x: 91.58, y: 93.06, z: 107.75}
164
+ ```
165
+
166
+ ### fuzzy
167
+
168
+ Name conversions by default look for exact matches between the hex value of the colour
169
+
170
+ ```ruby
171
+ colour = ColorConverters::Color.new(r: 175.8, g: 196.4, b: 222.1)
172
+
173
+ colour.name
174
+ => nil
175
+
176
+ colour.name(fuzzy: true)
177
+ => 'lightsteelblue'
178
+ ```
179
+
180
+ ## Development
181
+
182
+ [Converting Colors](https://convertingcolors.com/) and [Colorffy](https://colorffy.com/) can be used to help verify results. Different calculators use different exponents and standards so there can be discrepency across them (like this calculator for LCH).
183
+
184
+ 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.
185
+
186
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
187
+
188
+ ## Contributing
189
+
190
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/louiswdavis/color_converters>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/louiswdavis/color_converters/blob/master/CODE_OF_CONDUCT.md).
191
+
192
+ ## License
193
+
194
+ Forked from original gem by Derek DeVries.
195
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
196
+
197
+ ## Code of Conduct
198
+
199
+ Everyone interacting in the ColorConverters project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/louiswdavis/color_converters/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,8 +1,8 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- task default: :spec
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec