Skip to content

Instantly share code, notes, and snippets.

@e12e
Last active January 11, 2021 06:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e12e/7990e56f48ceff5506d7 to your computer and use it in GitHub Desktop.
Save e12e/7990e56f48ceff5506d7 to your computer and use it in GitHub Desktop.
Colors hack
#!/usr/bin/sh
image="${1}"
sz="100px"
for space in sRGB RGB HSV LAB
do
# I think it should be possible to do this without
# writing
# tiff-images to disk in-between -- but having a
# look at the
# resulting images next to the original is
# actually quite nice
# gives some idea of the differences
# colorspace makes:
convert "${image}" -quantize "${space}" +dither -colors 4 "${image}_${space}.tiff"
echo "Histogram in ${space} colorspace:"
convert "${image}_${space}.tiff" -format %c histogram:info:- | tee ${space}.txt
echo
done
colortable()
{
my_space="${1}"
echo "${my_space}:"
echo '<table><tr>'
sed -nre 's/.*(#[0-9A-F]{6}) .*/\1/p' "${my_space}.txt" | while read color
do
echo "<td style='width:${sz};height:${sz};background:${color}'>&nbsp;</td>"
done
echo '</tr></table>'
}
htmlhead()
{
cat > index.html <<eof
<html>
<pre>
<img src="./${image}" />
eof
}
middle()
{
for space in sRGB RGB HSV LAB
do
colortable "${space}" >> index.html
done
}
htmlepiloge()
{
cat >> index.html <<eof
</pre>
</html>
eof
}
htmlhead
middle
htmlepiloge
<html>
<style>
body {
background: black;
color: white;
}
td {
width: 100px;
height: 100px;
}
</style>
<pre>
<img src="https://gist.githubusercontent.com/e12e/7990e56f48ceff5506d7/raw/e9f5bd9ac442637d845aebb67a0a4f8b7658ec3a/akira.jpg" />
sRGB:
<table><tr>
</tr></table>
RGB:
<table><tr>
<td style='background:#2D2833'>&nbsp;</td>
<td style='background:#5D5664'>&nbsp;</td>
<td style='background:#8B777C'>&nbsp;</td>
<td style='background:#DA7D4A'>&nbsp;</td>
</tr></table>
HSV:
<table><tr>
<td style='background:#1E0D33'>&nbsp;</td>
<td style='background:#383450'>&nbsp;</td>
<td style='background:#3C1F0A'>&nbsp;</td>
<td style='background:#4E9B57'>&nbsp;</td>
</tr></table>
LAB:
<table><tr>
<td style='background:#2A293C'>&nbsp;</td>
<td style='background:#334857'>&nbsp;</td>
<td style='background:#58211B'>&nbsp;</td>
<td style='background:#977559'>&nbsp;</td>
</tr></table>
</pre>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment