34 lines
No EOL
871 B
C++
34 lines
No EOL
871 B
C++
#include <Magick++.h>
|
|
#include <napi.h>
|
|
|
|
#include <list>
|
|
|
|
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::Object>();
|
|
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
|
|
|
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<char>::Copy(env, (char *)blob.data(),
|
|
blob.length()));
|
|
result.Set("type", "jpg");
|
|
return result;
|
|
} catch (std::exception const &err) {
|
|
throw Napi::Error::New(env, err.what());
|
|
} catch (...) {
|
|
throw Napi::Error::New(env, "Unknown error");
|
|
}
|
|
} |