color_converters 0.1.2 → 0.1.4
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/README.md +190 -161
- data/lib/color_converters/base_converter.rb +184 -163
- data/lib/color_converters/color.rb +18 -16
- data/lib/color_converters/converters/cielab_converter.rb +95 -88
- data/lib/color_converters/converters/cielch_converter.rb +61 -52
- data/lib/color_converters/converters/cmyk_converter.rb +59 -56
- data/lib/color_converters/converters/hex_converter.rb +45 -32
- data/lib/color_converters/converters/hsl_converter.rb +68 -64
- data/lib/color_converters/converters/hsl_string_converter.rb +46 -25
- data/lib/color_converters/converters/hsv_converter.rb +60 -58
- data/lib/color_converters/converters/name_converter.rb +67 -183
- data/lib/color_converters/converters/null_converter.rb +19 -17
- data/lib/color_converters/converters/oklab_converter.rb +102 -0
- data/lib/color_converters/converters/oklch_converter.rb +61 -0
- data/lib/color_converters/converters/rgb_converter.rb +109 -29
- data/lib/color_converters/converters/rgb_string_converter.rb +49 -32
- data/lib/color_converters/converters/xyz_converter.rb +110 -127
- data/lib/color_converters/version.rb +1 -1
- data/lib/color_converters.rb +31 -28
- metadata +34 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9dbc30347819cfe3042c01530a7b28458f16286ca4267537148a86a918a684a
|
4
|
+
data.tar.gz: c8ce7ec66163f244f6714510acc883c8904275bea0ce0fada6bdcc364350b64a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87e552e208529b594de4302d56c645217b6cfad12018b58b12e6fc57bc3bef86170139c9c63d2268ef88f05953203b175950b20c7a3bb6decf69823926a8a8e3
|
7
|
+
data.tar.gz: 79cd6ad185469e763f30c5cede6d3de05c1b1ec5406c44e88b1bf9caae181480b2617e32108807e548a224f3661d9c769d1e98b16377bba36c4a3093534e1ec9
|
data/README.md
CHANGED
@@ -1,161 +1,190 @@
|
|
1
|
-
# Color Converters
|
2
|
-
|
3
|
-
> Give me a
|
4
|
-
|
5
|
-
Color Converters is an ruby gem package for use in ruby or other projects that provides conversions for
|
6
|
-
Given a
|
7
|
-
|
8
|
-
> Lab and LCH
|
9
|
-
|
10
|
-
## Converters
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
- hex
|
15
|
-
- rgb(a)
|
16
|
-
- hsl(a)
|
17
|
-
- hsv/hsb
|
18
|
-
- cmyk
|
19
|
-
- xyz
|
20
|
-
- cielab
|
21
|
-
-
|
22
|
-
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
```
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
```
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
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).
|