color_converters 0.1.3 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5cff79bc695fab4e8041206a798421948d03eb04933b77274a802f90a0010999
4
- data.tar.gz: 1edc8b8811b32ca6ac4d7b9f8347151ab772fa58d52d90ba4cd8f48ab60d889e
3
+ metadata.gz: b9dbc30347819cfe3042c01530a7b28458f16286ca4267537148a86a918a684a
4
+ data.tar.gz: c8ce7ec66163f244f6714510acc883c8904275bea0ce0fada6bdcc364350b64a
5
5
  SHA512:
6
- metadata.gz: a5fe55d89679198c41e0e166dbdae882b11f9396d58710b004707358652c6187e53889d88dd21efbeeee99b7738484a7cd3d71f7cc35496445881a9558fa9543
7
- data.tar.gz: 507da4fe02639e97285b5df4ed0e6e5e69fd78f793aa8bc772b2702d72e029f227ce50abf2987ac087fe1b050a06562262ed9660ca8395d6833e528412900852
6
+ metadata.gz: 87e552e208529b594de4302d56c645217b6cfad12018b58b12e6fc57bc3bef86170139c9c63d2268ef88f05953203b175950b20c7a3bb6decf69823926a8a8e3
7
+ data.tar.gz: 79cd6ad185469e763f30c5cede6d3de05c1b1ec5406c44e88b1bf9caae181480b2617e32108807e548a224f3661d9c769d1e98b16377bba36c4a3093534e1ec9
data/README.md CHANGED
@@ -1,176 +1,190 @@
1
- # Color Converters
2
-
3
- > Give me a color 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 colors to other color spaces.
6
- Given a color in [Hexadecimal, RGA(A), HSL(A), HSV, HSB, CMYK, XYZ, CIELAB, or OKLCH format](https://github.com/devrieda/color_conversion), it can convert the color to those other spaces.
7
-
8
- > Lab and LCH color spaces are special in that the perceived difference between two colors is proportional to their Euclidean distance in color space. This special property, called perceptual uniformity, makes them ideal for accurate visual encoding of data. In contrast, the more familiar RGB and HSL color spaces distort data when used for visualization.
9
-
10
- ## Converters
11
-
12
- Colors 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)
23
- - oklch (not always reliable)
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 color:
43
-
44
- ```ruby
45
- # from hex
46
- color = ColorConverters::Color.new("#3366cc")
47
- color = ColorConverters::Color.new("#36c")
48
-
49
- # from rgb(a)
50
- color = ColorConverters::Color.new(r: 51, g: 102, b: 204)
51
- color = ColorConverters::Color.new(r: 51, g: 102, b: 204, a: 0.5)
52
-
53
- # from hsl(a)
54
- color = ColorConverters::Color.new(h: 225, s: 73, l: 57)
55
- color = ColorConverters::Color.new(h: 225, s: 73, l: 57, a: 0.5)
56
-
57
- # from hsv/hsb
58
- color = ColorConverters::Color.new(h: 220, s: 75, v: 80)
59
- color = ColorConverters::Color.new(h: 220, s: 75, b: 80)
60
-
61
- # from cmyk
62
- color = ColorConverters::Color.new(c: 74, m: 58, y: 22, k: 3)
63
-
64
- # from xyz
65
- color = ColorConverters::Color.new(x: 16, y: 44, z: 32)
66
-
67
- # from cielab
68
- color = ColorConverters::Color.new(l: 16, a: 44, b: 32, space: :cie)
69
-
70
- # from cielch
71
- color = ColorConverters::Color.new(l: 16, c: 44, h: 32, space: :cie)
72
-
73
- # from oklab
74
- color = ColorConverters::Color.new(l: 16, a: 44, b: 32, space: :ok)
75
-
76
- # from oklch
77
- color = ColorConverters::Color.new(l: 16, c: 44, h: 32, space: :ok)
78
-
79
- # from textual color
80
- color = ColorConverters::Color.new("blue")
81
-
82
- # from a css rgb(a) string
83
- color = ColorConverters::Color.new("rgb(51, 102, 204)")
84
- color = ColorConverters::Color.new("rgba(51, 102, 204, 0.5)")
85
-
86
- # from a css hsl(a) string
87
- color = ColorConverters::Color.new("hsl(225, 73%, 57%)")
88
- color = ColorConverters::Color.new("hsl(225, 73%, 57%, 0.5)")
89
- ```
90
-
91
- Converters
92
-
93
- ```ruby
94
- color = ColorConverters::Color.new(r: 70, g: 130, b: 180, a: 0.5)
95
-
96
- color.alpha
97
- => 0.5
98
-
99
- color.rgb
100
- => {:r=>70, :g=>130, :b=>180}
101
-
102
- color.hsl
103
- => {:h=>207, :s=>44, :l=>49}
104
-
105
- color.hsv
106
- => {:h=>207, :s=>61, :v=>71}
107
-
108
- color.hsb
109
- => {:h=>207, :s=>61, :b=>71}
110
-
111
- color.cmyk
112
- => {:c=>61, :m=>28, :y=>0, :k=>29}
113
-
114
- color.xyz
115
- => {:x=>33, :y=>21, :z=>54}
116
-
117
- color.cielab
118
- => {:l=>52.47, :a=>-4.08, :b=>-32.19}
119
-
120
- color.cielch
121
- => {:l=>52.47, :c=>32.45, :h=>262.78}
122
-
123
- color.oklab # not always accurate
124
- => {:l=>52.47, :a=>-4.08, :b=>-32.19}
125
-
126
- color.oklch # not always accurate
127
- => {:l=>52.47, :c=>32.45, :h=>262.78}
128
-
129
- color.hex
130
- => "#4682b4"
131
-
132
- color.name
133
- => "steelblue"
134
- ```
135
-
136
- ## Options
137
-
138
- ### space
139
-
140
- As there are certain color 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
- ## Development
158
-
159
- [Converting Colors](https://convertingcolors.com/) and [Colorffy](https://colorffy.com/) can be usef to help verify results. Different calculators use different exponents and standards so there can be discrepency across them (like this calculator for LCH).
160
-
161
- 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.
162
-
163
- 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).
164
-
165
- ## Contributing
166
-
167
- 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).
168
-
169
- ## License
170
-
171
- Forked from original gem by Derek DeVries.
172
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
173
-
174
- ## Code of Conduct
175
-
176
- 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
+ > 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).