#include #include #include using namespace std; using namespace Magick; class SonicWorker : public Napi::AsyncWorker { public: SonicWorker(Napi::Function& callback, string text) : Napi::AsyncWorker(callback), text(text) {} ~SonicWorker() {} void Execute() { Image image; Image text_image; text_image.backgroundColor("none"); text_image.fontPointsize(72); text_image.textGravity(Magick::CenterGravity); text_image.font("Bitstream Vera Sans"); text_image.read("pango:" + text + ""); text_image.resize(Geometry(474, 332)); text_image.extent(Geometry("1024x538-435-145"), Magick::CenterGravity); image.read("./assets/images/sonic.jpg"); image.composite(text_image, Geometry("+160+10"), Magick::OverCompositeOp); image.magick("PNG"); image.write(&blob); } void OnOK() { Callback().Call({Env().Undefined(), Napi::Buffer::Copy(Env(), (char *)blob.data(), blob.length())}); } private: string text, type; int delay; Blob blob; }; Napi::Value Sonic(const Napi::CallbackInfo &info) { Napi::Env env = info.Env(); string text = info[0].As().Utf8Value(); Napi::Function cb = info[1].As(); SonicWorker* explodeWorker = new SonicWorker(cb, text); explodeWorker->Queue(); return env.Undefined(); }