mrmBot-Matrix/natives/sonic.cc
murm ff7f0a3110 Natives Rework (Thank you Essem)
Co-authored-by: Essem <TheEssem@users.noreply.github.com>
2023-03-19 04:40:32 -04:00

40 lines
No EOL
1.3 KiB
C++

#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
ArgumentMap Sonic(string type, string *outType, 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(("." + *outType).c_str(), &buf, DataSize);
ArgumentMap output;
output["buf"] = (char *)buf;
output["width"] = out.width();
output["height"] = vips_image_get_page_height(out.get_image());
return output;
}