Skip to content

Instantly share code, notes, and snippets.

@dartiss
Created April 24, 2023 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dartiss/565ad26a8ac1b0b34a43fb4f8ce21fb4 to your computer and use it in GitHub Desktop.
Save dartiss/565ad26a8ac1b0b34a43fb4f8ce21fb4 to your computer and use it in GitHub Desktop.
Hex to color name compression
$tocolor = array(
'#000080' => 'Navy',
'#008000' => 'Green',
'#008080' => 'Teal',
'#00FF00' => 'Lime',
'#4B0082' => 'Indigo',
'#800000' => 'Maroon',
'#800080' => 'Purple',
'#808000' => 'Olive',
'#808080' => 'Gray',
'#A0522D' => 'Sienna',
'#A52A2A' => 'Brown',
'#C0C0C0' => 'Silver',
'#CD853F' => 'Peru',
'#D2B48C' => 'Tan',
'#DA70D6' => 'Orchid',
'#DDA0DD' => 'Plum',
'#EE82EE' => 'Violet',
'#F0E68C' => 'Khaki',
'#F00' => 'Red',
'#F0FFFF' => 'Azure',
'#F5DEB3' => 'Wheat',
'#F5F5DC' => 'Beige',
'#FA8072' => 'Salmon',
'#FAF0E6' => 'Linen',
'#FF6347' => 'Tomato',
'#FF7F50' => 'Coral',
'#FFA500' => 'Orange',
'#FFC0CB' => 'Pink',
'#FFD700' => 'Gold',
'#FFE4C4' => 'Bisque',
'#FFFAFA' => 'Snow',
'#FFFFF0' => 'Ivory',
'#808080' => 'Grey',
);
@dartiss
Copy link
Author

dartiss commented Apr 24, 2023

This array can be used to replace hex colour values with their corresponding colour name, where the latter is shorter. In the case of the hex, I've assumed this has already been reduced to its minimum size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment