9
2
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!
7The file all not being one colour just seems like an unnecessary complication to me. And a falsey value in strongly typed languages, e.g. C#, can only be a
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? – TheLethalCoder – 2017-05-26T14:26:00.6605Also I suggest uploading your images to i.stack.imgur.com (my program can't get the image off of pasteboard) – user41805 – 2017-05-26T14:30:50.457
1
We have a default standard for image input, you can find it on our meta here. It's not significantly different from what you have, but you may want to link to it instead of your provided one.
– Pavel – 2017-05-26T14:32:28.8101@TheLethalCoder you could probably get away with returning
null
, or an empty string. – Pavel – 2017-05-26T14:35:24.8401@Phoenix That's what I'm asking though, is it okay as that is not a falsey value in C# and probably other strongly typed languages. – TheLethalCoder – 2017-05-26T14:36:15.863
@TheLethalCoder that's fine. Also the "it may be different colours is so that it isn't to trivial" – caird coinheringaahing – 2017-05-26T14:50:58.963
6
@Ilikemydog It does matter. Saying the output is "The only color in that file" leads answerers to assume that the image will contain a single color. Then the rules contradict that. On the other hand, it would be a lot clearer if the output section read something like "The only color in that file, or a falsy value different than... if the image contains more than one color". Or, as xnor so aptly put it, it's confusing when the body of the challenge says one thing but a later part says another
– Luis Mendo – 2017-05-26T15:23:22.840On a side note you can use the sandbox for future challenges to avoid most of this back and forth with clarifications once the challenge has already been posted.
– TheLethalCoder – 2017-05-26T15:26:31.7832Are we to assume that all files will always be 3 channel (8 bits each) RGB files? – Octopus – 2017-05-26T15:45:08.853
What @LuisMendo says is exactly what caused me to screw up my first attempt at this. – Shaggy – 2017-05-26T17:12:54.850
@Octopus yes you shoud – caird coinheringaahing – 2017-05-26T21:06:13.297
Can we only assume the format? – l4m2 – 2018-10-25T13:14:11.167