mrmBot-Matrix/natives/sonic.cc

38 lines
1.1 KiB
C++
Raw Normal View History

2022-12-26 06:28:56 +00:00
#include "common.h"
#include <vips/vips8>
2020-07-22 18:12:38 +00:00
using namespace std;
using namespace vips;
2020-07-22 18:12:38 +00:00
2022-12-26 06:28:56 +00:00
char *Sonic(string *type, ArgumentMap Arguments, size_t *DataSize) {
string text = GetArgument<string>(Arguments, "text");
string basePath = GetArgument<string>(Arguments, "basePath");
string assetPath = basePath + "assets/images/sonic.jpg";
VImage bg = VImage::new_from_file(assetPath.c_str());
VImage textImage =
VImage::text(
("<span foreground=\"white\">" + text + "</span>").c_str(),
VImage::option()
->set("rgba", true)
->set("align", VIPS_ALIGN_CENTRE)
->set("font", "Verdana, Twemoji Color Font")
->set("fontfile", (basePath + "assets/fonts/twemoji.otf").c_str())
->set("width", 542)
->set("height", 390))
.gravity(VIPS_COMPASS_DIRECTION_CENTRE, 542, 390);
VImage out = bg.composite2(textImage, VIPS_BLEND_MODE_OVER,
VImage::option()->set("x", 391)->set("y", 84));
void *buf;
out.write_to_buffer(".png", &buf, DataSize);
*type = "png";
2022-06-28 03:50:53 +00:00
vips_error_clear();
vips_thread_shutdown();
2022-12-26 06:28:56 +00:00
return (char *)buf;
2020-07-22 18:12:38 +00:00
}