You are to golf a program that will take a filename as input and you must output what color the file is.
The file will have any one of these extensions but your program only needs to support one. Please say which one in your answer.
.jpg
.png
.svg
.gif
.bmp
And now to the classic layout.
Input
A filename with one of the above extensions.
You may also take an image object or already encoded image instead.
Output
The only color in that file as a 6 digit hex code with an optional leading #
e.g. #000000
is black.
You may also output a list/tuple/string containing the decimal or hex values of the RGB color, with a clear, non-numeric delimiter e.g.
,
|
etc
You may not output the transparency.
If the file isn't all one color, you must output a falsy value that isn't #000000
and terminate without printing anything to STDERR
. This is so that you can't simply open the file and get the RGB value of the first pixel.
Rules
- The hex code only needs to be outputted if the file is all one color.
- The file will be
500x500
pixels - The pixels will all have 0% transparency.
- This is code-golf so shortest code wins!
bool
. For this case I'd be returning astring
for the normal case andbool
for the non-normal case, wrapped in anobject
. Is this fine or can I return an empty string or similar? \$\endgroup\$