2021-04-24 22:54:47 +00:00
|
|
|
#include <Magick++.h>
|
2020-07-21 14:03:08 +00:00
|
|
|
#include <napi.h>
|
2021-04-24 22:54:47 +00:00
|
|
|
|
2020-08-28 02:34:12 +00:00
|
|
|
#include <list>
|
2020-07-21 14:03:08 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Magick;
|
|
|
|
|
2021-04-24 22:54:47 +00:00
|
|
|
Napi::Value Homebrew(const Napi::CallbackInfo &info) {
|
2020-07-21 14:03:08 +00:00
|
|
|
Napi::Env env = info.Env();
|
|
|
|
|
2021-04-26 14:47:03 +00:00
|
|
|
try {
|
|
|
|
Napi::Object obj = info[0].As<Napi::Object>();
|
|
|
|
string caption = obj.Get("caption").As<Napi::String>().Utf8Value();
|
2020-07-21 14:03:08 +00:00
|
|
|
|
2021-04-26 14:47:03 +00:00
|
|
|
Blob blob;
|
2021-04-24 22:54:47 +00:00
|
|
|
|
2021-04-26 14:47:03 +00:00
|
|
|
Image image;
|
|
|
|
image.read("./assets/images/hbc.png");
|
|
|
|
image.textGravity(Magick::CenterGravity);
|
|
|
|
image.font("./assets/hbc.ttf");
|
|
|
|
image.textKerning(-5);
|
|
|
|
image.fillColor("white");
|
|
|
|
image.fontPointsize(96);
|
|
|
|
image.draw(DrawableText(0, 0, caption));
|
|
|
|
image.magick("PNG");
|
|
|
|
image.write(&blob);
|
2021-04-24 22:54:47 +00:00
|
|
|
|
2021-04-26 14:47:03 +00:00
|
|
|
Napi::Object result = Napi::Object::New(env);
|
|
|
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
|
|
|
blob.length()));
|
|
|
|
result.Set("type", "png");
|
|
|
|
return result;
|
2021-05-03 21:01:48 +00:00
|
|
|
} catch (Napi::Error const &err) {
|
|
|
|
throw err;
|
2021-04-26 14:47:03 +00:00
|
|
|
} catch (std::exception const &err) {
|
|
|
|
throw Napi::Error::New(env, err.what());
|
2021-05-03 21:01:48 +00:00
|
|
|
} catch (...) {
|
|
|
|
throw Napi::Error::New(env, "Unknown error");
|
2021-04-26 14:47:03 +00:00
|
|
|
}
|
2020-07-21 14:03:08 +00:00
|
|
|
}
|