forked from tastytea/libravatarserv
Deleted old identicon code.
This commit is contained in:
parent
41299b9529
commit
a909b0405c
|
@ -77,61 +77,3 @@ void image::write(Image &image)
|
||||||
cout.flush(); // We need to flush before we use /dev/stdout directly.
|
cout.flush(); // We need to flush before we use /dev/stdout directly.
|
||||||
image.image.write("/dev/stdout");
|
image.image.write("/dev/stdout");
|
||||||
}
|
}
|
||||||
|
|
||||||
Image image::identicon(const string &digest)
|
|
||||||
{
|
|
||||||
const string sha256 = hash::sha256(digest);
|
|
||||||
Magick::Image img(Magick::Geometry(4, 4), Magick::Color("white"));
|
|
||||||
// The 16 named colors specified in HTML 4.01 minus white, silver and gray.
|
|
||||||
const std::array<Magick::Color, 13> colors =
|
|
||||||
{
|
|
||||||
Magick::Color("black"),
|
|
||||||
Magick::Color("red"),
|
|
||||||
Magick::Color("maroon"),
|
|
||||||
Magick::Color("yellow"),
|
|
||||||
Magick::Color("olive"),
|
|
||||||
Magick::Color("lime"),
|
|
||||||
Magick::Color("green"),
|
|
||||||
Magick::Color("aqua"),
|
|
||||||
Magick::Color("teal"),
|
|
||||||
Magick::Color("blue"),
|
|
||||||
Magick::Color("navy"),
|
|
||||||
Magick::Color("fuchsia"),
|
|
||||||
Magick::Color("purple")
|
|
||||||
};
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
std::uint64_t random = 0xffffffffffffffff;
|
|
||||||
for (uint64_t chunk = 0; chunk < 4; ++chunk)
|
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << std::hex << sha256.substr(chunk * 16, 16);
|
|
||||||
random = (random / 2) + (static_cast<std::uint64_t>(ss.get()) / 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
Magick::Color dotcolor = colors[random % 13];
|
|
||||||
for (uint8_t row = 0; row < 4; ++row)
|
|
||||||
{
|
|
||||||
for (uint8_t column = 0; column < 4; ++column)
|
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
uint16_t px;
|
|
||||||
ss << std::hex << sha256.substr(row * 4 + column, 4);
|
|
||||||
ss >> px;
|
|
||||||
if (px > 0x8000)
|
|
||||||
{
|
|
||||||
img.pixelColor(column, row, dotcolor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (const std::exception &e)
|
|
||||||
{
|
|
||||||
cerr << "Error: " << e.what() << endl;
|
|
||||||
return { 5, img };
|
|
||||||
}
|
|
||||||
|
|
||||||
img.magick("png");
|
|
||||||
return { 0, img };
|
|
||||||
}
|
|
||||||
|
|
|
@ -134,18 +134,6 @@ int main()
|
||||||
cerr << "Error: Couldn't generate identicon ("
|
cerr << "Error: Couldn't generate identicon ("
|
||||||
<< e.what() << ").\n";
|
<< e.what() << ").\n";
|
||||||
}
|
}
|
||||||
// image = image::identicon(avatar.digest);
|
|
||||||
// // Magick::Image =
|
|
||||||
// if (image.error == 0)
|
|
||||||
// {
|
|
||||||
// image.image.scale(Magick::Geometry(avatar.size, avatar.size));
|
|
||||||
// image::write(image);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// cout << "Status: 500 Internal Server Error\n\n";
|
|
||||||
// cerr << "Error: Couldn't generate identicon.\n";
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue