File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed
Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -173,8 +173,11 @@ defmodule Image.Color do
173173 iex> Image.Color.rgb_to_hex(:green)
174174 {:ok, "#008000"}
175175
176- iex> Image.Color.rgb_to_hex([10,20,30])
177- {:ok, "#A141E"}
176+ iex> Image.Color.rgb_to_hex([10, 20, 30])
177+ {:ok, "#0A141E"}
178+
179+ iex> Image.Color.rgb_to_hex([12, 12, 13])
180+ {:ok, "#0C0C0D"}
178181
179182 """
180183 def rgb_to_hex ( color ) do
@@ -219,12 +222,10 @@ defmodule Image.Color do
219222 "#" <> to_hex ( r ) <> to_hex ( g ) <> to_hex ( b )
220223 end
221224
222- defp to_hex ( i ) when i >= 10 do
223- Integer . to_string ( i , 16 )
224- end
225-
226225 defp to_hex ( i ) do
227- "0" <> Integer . to_string ( i , 16 )
226+ i
227+ |> Integer . to_string ( 16 )
228+ |> String . pad_leading ( 2 , "0" )
228229 end
229230
230231 @ doc """
You can’t perform that action at this time.
0 commit comments