We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents e9f6826 + 2480133 commit 972d38dCopy full SHA for 972d38d
1 file changed
lib/image/color.ex
@@ -173,8 +173,11 @@ defmodule Image.Color do
173
iex> Image.Color.rgb_to_hex(:green)
174
{:ok, "#008000"}
175
176
- iex> Image.Color.rgb_to_hex([10,20,30])
177
- {:ok, "#A141E"}
+ iex> Image.Color.rgb_to_hex([10, 20, 30])
+ {:ok, "#0A141E"}
178
+
179
+ iex> Image.Color.rgb_to_hex([12, 12, 13])
180
+ {:ok, "#0C0C0D"}
181
182
"""
183
def rgb_to_hex(color) do
@@ -219,12 +222,10 @@ defmodule Image.Color do
219
222
"#" <> to_hex(r) <> to_hex(g) <> to_hex(b)
220
223
end
221
224
- defp to_hex(i) when i >= 10 do
- Integer.to_string(i, 16)
- end
225
-
226
defp to_hex(i) do
227
- "0" <> Integer.to_string(i, 16)
+ i
+ |> Integer.to_string(16)
228
+ |> String.pad_leading(2, "0")
229
230
231
@doc """
0 commit comments