#include #include #include using namespace std; using namespace Magick; Napi::Value Jpeg(const Napi::CallbackInfo &info) { Napi::Env env = info.Env(); try { Napi::Object obj = info[0].As(); Napi::Buffer data = obj.Get("data").As>(); Blob blob; Image image; image.read(Blob(data.Data(), data.Length())); image.quality(1); image.magick("JPEG"); image.write(&blob); Napi::Object result = Napi::Object::New(env); result.Set("data", Napi::Buffer::Copy(env, (char *)blob.data(), blob.length())); result.Set("type", "jpg"); return result; } catch (Napi::Error const &err) { throw err; } catch (std::exception const &err) { throw Napi::Error::New(env, err.what()); } catch (...) { throw Napi::Error::New(env, "Unknown error"); } }