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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 571bd439610154032f4532335702ecb175cd3b022b966843b81ebc26c12a5411
4
- data.tar.gz: 33dad1ab16c74560c7fd4587392400002cc863ee16e77bff739e28577f1b9451
3
+ metadata.gz: b9dbc30347819cfe3042c01530a7b28458f16286ca4267537148a86a918a684a
4
+ data.tar.gz: c8ce7ec66163f244f6714510acc883c8904275bea0ce0fada6bdcc364350b64a
5
5
  SHA512:
6
- metadata.gz: 6c9138a8fa458032dfcc2319a2d188a545e9042cfe740d168b737a5d984b4ec94501efce7d384a54baf3ea717384e6b9cc0fbebc8d085a2eb46c24879fa2cefb
7
- data.tar.gz: 5cdd92b601b6458552e617413ff4cd1b884571009d5d565e727e47d57da202feb9e9b4b6a6e8ac0fd2592b612b055bc9aa78cbe530f85336bc5fb0d2a07ed236
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 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
- - oklch
22
- - name
23
-
24
- ## Installation
25
-
26
- Install the gem and add to the application's Gemfile by executing:
27
-
28
- ```bash
29
- bundle add color_converters
30
- ```
31
-
32
- If bundler is not being used to manage dependencies, install the gem by executing:
33
-
34
- ```bash
35
- gem install color_converters
36
- ```
37
-
38
- ## Usage
39
-
40
- Initialize a color:
41
-
42
- ```ruby
43
- # from hex
44
- color = ColorConverters::Color.new("#3366cc")
45
- color = ColorConverters::Color.new("#36c")
46
-
47
- # from rgb(a)
48
- color = ColorConverters::Color.new(r: 51, g: 102, b: 204)
49
- color = ColorConverters::Color.new(r: 51, g: 102, b: 204, a: 0.5)
50
-
51
- # from hsl(a)
52
- color = ColorConverters::Color.new(h: 225, s: 73, l: 57)
53
- color = ColorConverters::Color.new(h: 225, s: 73, l: 57, a: 0.5)
54
-
55
- # from hsv/hsb
56
- color = ColorConverters::Color.new(h: 220, s: 75, v: 80)
57
- color = ColorConverters::Color.new(h: 220, s: 75, b: 80)
58
-
59
- # from cmyk
60
- color = ColorConverters::Color.new(c: 74, m: 58, y: 22, k: 3)
61
-
62
- # from xyz
63
- color = ColorConverters::Color.new(x: 16, y: 44, z: 32)
64
-
65
- # from cielab
66
- color = ColorConverters::Color.new(l: 16, a: 44, b: 32, space: :cie)
67
-
68
- # from cielch
69
- color = ColorConverters::Color.new(l: 16, c: 44, h: 32, space: :cie)
70
-
71
- # from textual color
72
- color = ColorConverters::Color.new("blue")
73
-
74
- # from a css rgb(a) string
75
- color = ColorConverters::Color.new("rgb(51, 102, 204)")
76
- color = ColorConverters::Color.new("rgba(51, 102, 204, 0.5)")
77
-
78
- # from a css hsl(a) string
79
- color = ColorConverters::Color.new("hsl(225, 73%, 57%)")
80
- color = ColorConverters::Color.new("hsl(225, 73%, 57%, 0.5)")
81
- ```
82
-
83
- Converters
84
-
85
- ```ruby
86
- color = ColorConverters::Color.new(r: 70, g: 130, b: 180, a: 0.5)
87
-
88
- color.alpha
89
- => 0.5
90
-
91
- color.rgb
92
- => {:r=>70, :g=>130, :b=>180}
93
-
94
- color.hsl
95
- => {:h=>207, :s=>44, :l=>49}
96
-
97
- color.hsv
98
- => {:h=>207, :s=>61, :v=>71}
99
-
100
- color.hsb
101
- => {:h=>207, :s=>61, :b=>71}
102
-
103
- color.cmyk
104
- => {:c=>61, :m=>28, :y=>0, :k=>29}
105
-
106
- color.xyz
107
- => {:x=>33, :y=>21, :z=>54}
108
-
109
- color.cielab
110
- => {:l=>52.47, :a=>-4.08, :b=>-32.19}
111
-
112
- color.cielch
113
- => {:l=>52.47, :c=>32.45, :h=>262.78}
114
-
115
- color.hex
116
- => "#4682b4"
117
-
118
- color.name
119
- => "steelblue"
120
- ```
121
-
122
- ## Options
123
-
124
- ### space
125
-
126
- As there are certain color spaces that use the same letter keys, there needed to be a way to different between those space.
127
- The space parameter allows that, with examples in the usage code above
128
-
129
- ```ruby
130
- ColorConverters::Color.new(l: 64, a: 28, b: -15, space: :cie)
131
- ```
132
-
133
- ### limit_override
134
-
135
- By default all values are checked to be within the expected number ranges, i.e.; rgb between 0-255 each.
136
- This parameter allows you to ignore those ranges and submit any values you want.
137
-
138
- ```ruby
139
- ColorConverters::Color.new(r: 270, g: 1300, b: 380, a: 0.5, limit_override: true)
140
- ```
141
-
142
- ## Development
143
-
144
- [Converting Colors](https://convertingcolors.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).
145
-
146
- 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.
147
-
148
- 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).
149
-
150
- ## Contributing
151
-
152
- 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).
153
-
154
- ## License
155
-
156
- Forked from original gem by Derek DeVries.
157
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
158
-
159
- ## Code of Conduct
160
-
161
- 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).