Natives Rework (Thank you Essem)
Co-authored-by: Essem <TheEssem@users.noreply.github.com>
This commit is contained in:
parent
b424b2f813
commit
ff7f0a3110
88 changed files with 3358 additions and 3104 deletions
40
app.js
40
app.js
|
@ -75,27 +75,27 @@ async function* getFiles(dir) {
|
|||
async function init() {
|
||||
await exec("git rev-parse HEAD").then(output => output.stdout.substring(0, 7), () => "unknown commit").then(o => process.env.GIT_REV = o);
|
||||
console.log(`
|
||||
,*\`$ z\`"v
|
||||
F zBw\`% A ,W "W
|
||||
,\` ,EBBBWp"%. ,-=~~==-,+* 4BBE T
|
||||
M BBBBBBBB* ,w=####Wpw 4BBBBB# 1
|
||||
F BBBBBBBMwBBBBBBBBBBBBB#wXBBBBBH E
|
||||
F BBBBBBkBBBBBBBBBBBBBBBBBBBBE4BL k
|
||||
# BFBBBBBBBBBBBBF" "RBBBW F
|
||||
V ' 4BBBBBBBBBBM TBBL F
|
||||
F BBBBBBBBBBF JBB L
|
||||
F FBBBBBBBEB BBL 4
|
||||
E [BB4BBBBEBL BBL 4
|
||||
I #BBBBBBBEB 4BBH *w
|
||||
A 4BBBBBBBBBEW, ,BBBB W [
|
||||
.A ,k 4BBBBBBBBBBBEBW####BBBBBBM BF F
|
||||
k <BBBw BBBBEBBBBBBBBBBBBBBBBBQ4BM #
|
||||
5, REBBB4BBBBB#BBBBBBBBBBBBP5BFF ,F
|
||||
*w \`*4BBW\`"FF#F##FFFF"\` , * +"
|
||||
*+, " F'"'*^~~~^"^\` V+*^
|
||||
\`"""
|
||||
████
|
||||
████▒▒▒▒
|
||||
████▒▒████▒▒
|
||||
████▒▒██████▒▒
|
||||
████▒▒██████████▒▒
|
||||
████▒▒████████████▒▒
|
||||
████▒▒██████████████▒▒
|
||||
████▒▒██████████████▒▒▒▒
|
||||
████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
|
||||
████▒▒████████████▒▒██▒▒██▒▒
|
||||
████▒▒██████████▒▒████▒▒████▒▒
|
||||
████▒▒██████▒▒██████▒▒██████▒▒
|
||||
████▒▒████▒▒████████▒▒████████▒▒
|
||||
████▒▒▒▒██████████▒▒██████████▒▒
|
||||
████▒▒██████████▒▒██████████▒▒██
|
||||
████▒▒▒▒▒▒████▒▒████▒▒▒▒▒▒████
|
||||
████████▒▒▒▒▒▒▒▒▒▒████████
|
||||
██████████████████████
|
||||
██████████
|
||||
|
||||
esmBot ${esmBotVersion} (${process.env.GIT_REV})
|
||||
mrmBot-matrix ${esmBotVersion} (${process.env.GIT_REV})
|
||||
`);
|
||||
|
||||
if (!types.classic && !types.application) {
|
||||
|
|
|
@ -79,14 +79,17 @@ class ImageCommand extends Command {
|
|||
}
|
||||
|
||||
try {
|
||||
const { buffer, type } = await runImageJob(imageParams);
|
||||
const { buffer, type, width, height } = await runImageJob(imageParams);
|
||||
if (type === "nogif" && this.constructor.requiresGIF) {
|
||||
return "That isn't a GIF!";
|
||||
}
|
||||
this.success = true;
|
||||
return {
|
||||
contents: buffer,
|
||||
name: `${this.constructor.command}.${type}`
|
||||
name: `${this.constructor.command}.${type}`,
|
||||
type,
|
||||
width,
|
||||
height
|
||||
};
|
||||
} catch (e) {
|
||||
if (e === "Request ended prematurely due to a closed connection") return "This image job couldn't be completed because the server it was running on went down. Try running your command again.";
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
import ImageCommand from "../../classes/imageCommand.js";
|
||||
|
||||
class ExplodeCommand extends ImageCommand {
|
||||
params = {
|
||||
implode: false
|
||||
};
|
||||
|
||||
static category = "image-editing"
|
||||
static description = "Explodes an image";
|
||||
static aliases = ["exp"];
|
||||
|
|
|
@ -2,6 +2,9 @@ import ImageCommand from "../../classes/imageCommand.js";
|
|||
|
||||
class FlipCommand extends ImageCommand {
|
||||
static category = "image-editing"
|
||||
params = {
|
||||
flop: false
|
||||
};
|
||||
static description = "Flips an image";
|
||||
|
||||
static noImage = "You need to provide an image/GIF to flip!";
|
||||
|
|
|
@ -99,11 +99,15 @@ export default async function (matrixClient, event, room, toStartOfTimeline) {
|
|||
} else {
|
||||
const mxcUri = await matrixClient.uploadContent(result.contents);
|
||||
// TODO: make info object get width, height, and mime from natives so i dont need to read the buffer
|
||||
const imgsize = sizeOf(result.contents)
|
||||
let mime = imgsize.type;
|
||||
if (mime == "jpg") {
|
||||
mime = "jpeg";
|
||||
// const imgsize = sizeOf(result.contents)
|
||||
const mime = result.type;
|
||||
const imgsize = {
|
||||
width: result.width,
|
||||
height: result.height
|
||||
}
|
||||
// if (mime === "jpg") {
|
||||
// mime = "jpeg";
|
||||
// }
|
||||
await matrixClient.sendImageMessage(event.event.room_id, mxcUri.content_uri, {h: imgsize.height, w: imgsize.width, mimetype: `image/${mime}`, size: result.contents.length, thumbnail_info: {h: imgsize.height, w: imgsize.width, mimetype: `image/${mime}`, size: result.contents.length}}, result.name)
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Blur(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Blur(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t *DataSize) {
|
||||
bool sharp = GetArgument<bool>(Arguments, "sharp");
|
||||
VOption *options = VImage::option()->set("access", "sequential");
|
||||
|
@ -27,5 +27,10 @@ char *Blur(string type, string *outType, char *BufferData, size_t BufferLength,
|
|||
void *buf;
|
||||
out.write_to_buffer(("." + *outType).c_str(), &buf, DataSize);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = out.width();
|
||||
output["height"] = vips_image_get_page_height(in.get_image());
|
||||
|
||||
return output;
|
||||
}
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Blur(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Blur(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -7,7 +7,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Bounce(string type, string *outType, char *BufferData,
|
||||
ArgumentMap Bounce(string type, string *outType, char *BufferData,
|
||||
size_t BufferLength, [[maybe_unused]] ArgumentMap Arguments,
|
||||
size_t *DataSize) {
|
||||
VOption *options = VImage::option();
|
||||
|
@ -47,5 +47,10 @@ char *Bounce(string type, string *outType, char *BufferData,
|
|||
|
||||
*outType = "gif";
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = width;
|
||||
output["height"] = pageHeight + halfHeight;
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Bounce(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Bounce(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -6,7 +6,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Caption(string type, string *outType, char *BufferData,
|
||||
ArgumentMap Caption(string type, string *outType, char *BufferData,
|
||||
size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
|
||||
string caption = GetArgument<string>(Arguments, "caption");
|
||||
string font = GetArgument<string>(Arguments, "font");
|
||||
|
@ -73,5 +73,10 @@ char *Caption(string type, string *outType, char *BufferData,
|
|||
? VImage::option()->set("dither", 0)->set("reoptimise", 1)
|
||||
: 0);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = final.width();
|
||||
output["height"] = vips_image_get_page_height(in.get_image());
|
||||
|
||||
return output;
|
||||
}
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Caption(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Caption(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -7,7 +7,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *CaptionTwo(string type, string *outType, char *BufferData,
|
||||
ArgumentMap CaptionTwo(string type, string *outType, char *BufferData,
|
||||
size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
|
||||
bool top = GetArgument<bool>(Arguments, "top");
|
||||
string caption = GetArgument<string>(Arguments, "caption");
|
||||
|
@ -77,5 +77,10 @@ char *CaptionTwo(string type, string *outType, char *BufferData,
|
|||
? VImage::option()->set("dither", 0)->set("reoptimise", 1)
|
||||
: 0);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = final.width();
|
||||
output["height"] = vips_image_get_page_height(in.get_image());
|
||||
|
||||
return output;
|
||||
}
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* CaptionTwo(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap CaptionTwo(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -11,7 +11,7 @@
|
|||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
char *Circle(string type, string *outType, char *BufferData,
|
||||
ArgumentMap Circle(string type, string *outType, char *BufferData,
|
||||
size_t BufferLength, [[maybe_unused]] ArgumentMap Arguments,
|
||||
size_t *DataSize) {
|
||||
Blob blob;
|
||||
|
@ -50,5 +50,11 @@ char *Circle(string type, string *outType, char *BufferData,
|
|||
// workaround because the data is tied to the blob
|
||||
char *data = (char *)malloc(*DataSize);
|
||||
memcpy(data, blob.data(), *DataSize);
|
||||
return data;
|
||||
|
||||
ArgumentMap output;
|
||||
output["buf"] = data;
|
||||
output["width"] = (int)blurred.front().columns();
|
||||
output["height"] = (int)blurred.front().rows();
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Circle(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Circle(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -10,7 +10,7 @@ using namespace vips;
|
|||
VImage sepia = VImage::new_matrixv(3, 3, 0.3588, 0.7044, 0.1368, 0.2990, 0.5870,
|
||||
0.1140, 0.2392, 0.4696, 0.0912);
|
||||
|
||||
char *Colors(string type, string *outType, char *BufferData,
|
||||
ArgumentMap Colors(string type, string *outType, char *BufferData,
|
||||
size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
|
||||
string color = GetArgument<string>(Arguments, "color");
|
||||
|
||||
|
@ -32,5 +32,10 @@ char *Colors(string type, string *outType, char *BufferData,
|
|||
void *buf;
|
||||
out.write_to_buffer(("." + *outType).c_str(), &buf, DataSize);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = out.width();
|
||||
output["height"] = vips_image_get_page_height(in.get_image());
|
||||
|
||||
return output;
|
||||
}
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Colors(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Colors(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -9,7 +9,7 @@ using std::map;
|
|||
using std::string;
|
||||
using std::variant;
|
||||
|
||||
typedef variant<string, float, bool, int> ArgumentVariant;
|
||||
typedef variant<char*, string, float, bool, int> ArgumentVariant;
|
||||
typedef map<string, ArgumentVariant> ArgumentMap;
|
||||
|
||||
#include "blur.h"
|
||||
|
@ -85,7 +85,7 @@ const std::unordered_map<std::string, std::string> fontPaths{
|
|||
{"roboto", "assets/fonts/reddit.ttf"}};
|
||||
|
||||
const std::map<std::string,
|
||||
char* (*)(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap (*)(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize)>
|
||||
FunctionMap = {{"blur", &Blur},
|
||||
{"bounce", &Bounce},
|
||||
|
@ -126,5 +126,5 @@ const std::map<std::string,
|
|||
{"zamn", Zamn}};
|
||||
|
||||
const std::map<std::string,
|
||||
char* (*)(string type, string* outType, ArgumentMap Arguments, size_t* DataSize)>
|
||||
ArgumentMap (*)(string type, string* outType, ArgumentMap Arguments, size_t* DataSize)>
|
||||
NoInputFunctionMap = {{"homebrew", Homebrew}, {"sonic", Sonic}};
|
|
@ -7,7 +7,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Crop(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Crop(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
[[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) {
|
||||
VOption *options = VImage::option()->set("access", "sequential");
|
||||
|
||||
|
@ -47,5 +47,10 @@ char *Crop(string type, string *outType, char *BufferData, size_t BufferLength,
|
|||
? VImage::option()->set("dither", 0)->set("reoptimise", 1)
|
||||
: 0);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = width;
|
||||
output["height"] = finalHeight;
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Crop(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Crop(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -6,7 +6,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Deepfry(string type, string *outType, char *BufferData,
|
||||
ArgumentMap Deepfry(string type, string *outType, char *BufferData,
|
||||
size_t BufferLength, [[maybe_unused]] ArgumentMap Arguments,
|
||||
size_t *DataSize) {
|
||||
VOption *options = VImage::option()->set("access", "sequential");
|
||||
|
@ -57,5 +57,10 @@ char *Deepfry(string type, string *outType, char *BufferData,
|
|||
("." + *outType).c_str(), &buf, DataSize,
|
||||
*outType == "gif" ? VImage::option()->set("dither", 0) : 0);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = width;
|
||||
output["height"] = pageHeight;
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Deepfry(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Deepfry(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -5,7 +5,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Explode(string type, string *outType, char *BufferData,
|
||||
ArgumentMap Explode(string type, string *outType, char *BufferData,
|
||||
size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
|
||||
bool implode = GetArgumentWithFallback<bool>(Arguments, "implode", false);
|
||||
string basePath = GetArgument<string>(Arguments, "basePath");
|
||||
|
@ -48,5 +48,10 @@ char *Explode(string type, string *outType, char *BufferData,
|
|||
void *buf;
|
||||
final.write_to_buffer(("." + *outType).c_str(), &buf, DataSize);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = width;
|
||||
output["height"] = pageHeight;
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Explode(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Explode(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -5,7 +5,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Flag(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Flag(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t *DataSize) {
|
||||
string overlay = GetArgument<string>(Arguments, "overlay");
|
||||
string basePath = GetArgument<string>(Arguments, "basePath");
|
||||
|
@ -45,5 +45,10 @@ char *Flag(string type, string *outType, char *BufferData, size_t BufferLength,
|
|||
? VImage::option()->set("dither", 0)->set("reoptimise", 1)
|
||||
: 0);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = width;
|
||||
output["height"] = pageHeight;
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Flag(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Flag(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -6,9 +6,9 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Flip(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Flip(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t *DataSize) {
|
||||
bool flop = GetArgument<bool>(Arguments, "flop");
|
||||
bool flop = GetArgumentWithFallback<bool>(Arguments, "flop", false);
|
||||
|
||||
VImage in = VImage::new_from_buffer(BufferData, BufferLength, "",
|
||||
type == "gif"
|
||||
|
@ -44,5 +44,10 @@ char *Flip(string type, string *outType, char *BufferData, size_t BufferLength,
|
|||
? VImage::option()->set("dither", 0)->set("reoptimise", 1)
|
||||
: 0);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = out.width();
|
||||
output["height"] = vips_image_get_page_height(in.get_image());
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Flip(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Flip(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -7,7 +7,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Freeze(string type, string *outType, char *BufferData,
|
||||
ArgumentMap Freeze(string type, string *outType, char *BufferData,
|
||||
size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
|
||||
bool loop = GetArgumentWithFallback<bool>(Arguments, "loop", false);
|
||||
int frame = GetArgumentWithFallback<int>(Arguments, "frame", -1);
|
||||
|
@ -42,7 +42,16 @@ char *Freeze(string type, string *outType, char *BufferData,
|
|||
}
|
||||
if (none) *DataSize = BufferLength;
|
||||
|
||||
return newData;
|
||||
VImage in =
|
||||
VImage::new_from_buffer(newData, *DataSize, "",
|
||||
VImage::option()->set("access", "sequential"));
|
||||
|
||||
ArgumentMap output;
|
||||
output["buf"] = newData;
|
||||
output["width"] = in.width();
|
||||
output["height"] = vips_image_get_page_height(in.get_image());
|
||||
|
||||
return output;
|
||||
} else if (frame >= 0 && !loop) {
|
||||
VOption *options = VImage::option()->set("access", "sequential");
|
||||
|
||||
|
@ -62,7 +71,13 @@ char *Freeze(string type, string *outType, char *BufferData,
|
|||
void *buf;
|
||||
out.write_to_buffer(("." + *outType).c_str(), &buf, DataSize);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = out.width();
|
||||
output["height"] = vips_image_get_page_height(in.get_image());
|
||||
|
||||
return output;
|
||||
|
||||
} else {
|
||||
lastPos = (char *)memchr(fileData, '\x21', BufferLength);
|
||||
while (lastPos != NULL) {
|
||||
|
@ -78,6 +93,15 @@ char *Freeze(string type, string *outType, char *BufferData,
|
|||
}
|
||||
if (none) *DataSize = BufferLength;
|
||||
|
||||
return fileData;
|
||||
VImage in =
|
||||
VImage::new_from_buffer(fileData, *DataSize, "",
|
||||
VImage::option()->set("access", "sequential"));
|
||||
|
||||
ArgumentMap output;
|
||||
output["buf"] = fileData;
|
||||
output["width"] = in.width();
|
||||
output["height"] = vips_image_get_page_height(in.get_image());
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Freeze(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Freeze(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -5,7 +5,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Gamexplain(string type, string *outType, char *BufferData,
|
||||
ArgumentMap Gamexplain(string type, string *outType, char *BufferData,
|
||||
size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
|
||||
string basePath = GetArgument<string>(Arguments, "basePath");
|
||||
|
||||
|
@ -46,5 +46,10 @@ char *Gamexplain(string type, string *outType, char *BufferData,
|
|||
? VImage::option()->set("dither", 0)->set("reoptimise", 1)
|
||||
: 0);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = final.width();
|
||||
output["height"] = vips_image_get_page_height(in.get_image());
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Gamexplain(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Gamexplain(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -5,7 +5,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Globe(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Globe(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t *DataSize) {
|
||||
string basePath = GetArgument<string>(Arguments, "basePath");
|
||||
|
||||
|
@ -69,5 +69,10 @@ char *Globe(string type, string *outType, char *BufferData, size_t BufferLength,
|
|||
void *buf;
|
||||
final.write_to_buffer(".gif", &buf, DataSize);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = final.width();
|
||||
output["height"] = vips_image_get_page_height(in.get_image());
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Globe(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Globe(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -5,7 +5,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Homebrew(string type, string *outType, ArgumentMap Arguments,
|
||||
ArgumentMap Homebrew(string type, string *outType, ArgumentMap Arguments,
|
||||
size_t *DataSize) {
|
||||
string caption = GetArgument<string>(Arguments, "caption");
|
||||
string basePath = GetArgument<string>(Arguments, "basePath");
|
||||
|
@ -33,5 +33,10 @@ char *Homebrew(string type, string *outType, ArgumentMap Arguments,
|
|||
void *buf;
|
||||
out.write_to_buffer(("." + *outType).c_str(), &buf, DataSize);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = bg.width();
|
||||
output["height"] = vips_image_get_page_height(bg.get_image());
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,4 +4,4 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char *Homebrew(string type, string *outType, ArgumentMap Arguments, size_t *DataSize);
|
||||
ArgumentMap Homebrew(string type, string *outType, ArgumentMap Arguments, size_t *DataSize);
|
|
@ -5,7 +5,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Invert(string type, string *outType, char *BufferData,
|
||||
ArgumentMap Invert(string type, string *outType, char *BufferData,
|
||||
size_t BufferLength, [[maybe_unused]] ArgumentMap Arguments,
|
||||
size_t *DataSize) {
|
||||
VOption *options = VImage::option()->set("access", "sequential");
|
||||
|
@ -24,5 +24,10 @@ char *Invert(string type, string *outType, char *BufferData,
|
|||
void *buf;
|
||||
out.write_to_buffer(("." + *outType).c_str(), &buf, DataSize);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = out.width();
|
||||
output["height"] = vips_image_get_page_height(in.get_image());
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Invert(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Invert(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -5,11 +5,13 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Jpeg(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Jpeg(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t *DataSize) {
|
||||
int quality = GetArgumentWithFallback<int>(Arguments, "quality", 0);
|
||||
|
||||
void *buf;
|
||||
ArgumentMap output;
|
||||
|
||||
|
||||
if (type == "gif") {
|
||||
VImage in = VImage::new_from_buffer(
|
||||
|
@ -55,6 +57,9 @@ char *Jpeg(string type, string *outType, char *BufferData, size_t BufferLength,
|
|||
final.write_to_buffer(
|
||||
("." + *outType).c_str(), &buf, DataSize,
|
||||
*outType == "gif" ? VImage::option()->set("dither", 0) : 0);
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = width;
|
||||
output["height"] = pageHeight;
|
||||
} else {
|
||||
VImage in = VImage::new_from_buffer(BufferData, BufferLength, "");
|
||||
void *jpgBuf;
|
||||
|
@ -69,7 +74,10 @@ char *Jpeg(string type, string *outType, char *BufferData, size_t BufferLength,
|
|||
*outType = "jpg";
|
||||
buf = jpgBuf;
|
||||
}
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = in.width();
|
||||
output["height"] = vips_image_get_page_height(in.get_image());
|
||||
}
|
||||
|
||||
return (char *)buf;
|
||||
return output;
|
||||
}
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Jpeg(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Jpeg(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -9,7 +9,7 @@
|
|||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
char *Magik(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Magik(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
[[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) {
|
||||
Blob blob;
|
||||
|
||||
|
@ -48,5 +48,11 @@ char *Magik(string type, string *outType, char *BufferData, size_t BufferLength,
|
|||
|
||||
char *data = (char *)malloc(*DataSize);
|
||||
memcpy(data, blob.data(), *DataSize);
|
||||
return data;
|
||||
|
||||
ArgumentMap output;
|
||||
output["buf"] = data;
|
||||
output["width"] = (int)blurred.front().columns();
|
||||
output["height"] = (int)blurred.front().rows();
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Magik(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Magik(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -5,7 +5,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Meme(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Meme(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t *DataSize) {
|
||||
string top = GetArgument<string>(Arguments, "top");
|
||||
string bottom = GetArgument<string>(Arguments, "bottom");
|
||||
|
@ -135,5 +135,10 @@ char *Meme(string type, string *outType, char *BufferData, size_t BufferLength,
|
|||
? VImage::option()->set("dither", 0)->set("reoptimise", 1)
|
||||
: 0);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = width;
|
||||
output["height"] = pageHeight;
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Meme(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Meme(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -5,7 +5,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Mirror(string type, string *outType, char *BufferData,
|
||||
ArgumentMap Mirror(string type, string *outType, char *BufferData,
|
||||
size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
|
||||
bool vertical = GetArgumentWithFallback<bool>(Arguments, "vertical", false);
|
||||
bool first = GetArgumentWithFallback<bool>(Arguments, "first", false);
|
||||
|
@ -60,5 +60,10 @@ char *Mirror(string type, string *outType, char *BufferData,
|
|||
void *buf;
|
||||
out.write_to_buffer(("." + *outType).c_str(), &buf, DataSize);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = in.width();
|
||||
output["height"] = vips_image_get_page_height(in.get_image());
|
||||
|
||||
return output;
|
||||
}
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Mirror(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Mirror(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -5,7 +5,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Motivate(string type, string *outType, char *BufferData,
|
||||
ArgumentMap Motivate(string type, string *outType, char *BufferData,
|
||||
size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
|
||||
string top_text = GetArgument<string>(Arguments, "top");
|
||||
string bottom_text = GetArgument<string>(Arguments, "bottom");
|
||||
|
@ -119,5 +119,10 @@ char *Motivate(string type, string *outType, char *BufferData,
|
|||
("." + *outType).c_str(), &buf, DataSize,
|
||||
*outType == "gif" ? VImage::option()->set("dither", 1) : 0);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = in.width();
|
||||
output["height"] = vips_image_get_page_height(in.get_image());
|
||||
|
||||
return output;
|
||||
}
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Motivate(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Motivate(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -67,25 +67,31 @@ Napi::Value ProcessImage(const Napi::CallbackInfo& info) {
|
|||
string outType = GetArgument<bool>(Arguments, "togif") ? "gif" : type;
|
||||
|
||||
size_t length = 0;
|
||||
char* buf;
|
||||
ArgumentMap outMap;
|
||||
if (obj.Has("data")) {
|
||||
Napi::Buffer<char> data = obj.Has("data")
|
||||
? obj.Get("data").As<Napi::Buffer<char>>()
|
||||
: Napi::Buffer<char>::New(env, 0);
|
||||
buf = FunctionMap.at(command)(type, &outType, data.Data(), data.Length(),
|
||||
outMap = FunctionMap.at(command)(type, &outType, data.Data(), data.Length(),
|
||||
Arguments, &length);
|
||||
} else {
|
||||
buf = NoInputFunctionMap.at(command)(type, &outType, Arguments, &length);
|
||||
outMap = NoInputFunctionMap.at(command)(type, &outType, Arguments, &length);
|
||||
}
|
||||
|
||||
vips_error_clear();
|
||||
vips_thread_shutdown();
|
||||
|
||||
char* buf = GetArgument<char*>(outMap, "buf");
|
||||
int width = GetArgument<int>(outMap, "width");
|
||||
int height = GetArgument<int>(outMap, "height");
|
||||
|
||||
result.Set("data",
|
||||
Napi::Buffer<char>::New(env, buf, length,
|
||||
[]([[maybe_unused]] Napi::Env env,
|
||||
void* data) { free(data); }));
|
||||
result.Set("type", outType);
|
||||
result.Set("width", width);
|
||||
result.Set("height", height);
|
||||
} catch (std::exception const& err) {
|
||||
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
|
||||
} catch (...) {
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Reddit(string type, string *outType, char *BufferData,
|
||||
ArgumentMap Reddit(string type, string *outType, char *BufferData,
|
||||
size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
|
||||
string text = GetArgumentWithFallback<string>(Arguments, "text", "");
|
||||
string text = GetArgument<string>(Arguments, "caption");
|
||||
string basePath = GetArgument<string>(Arguments, "basePath");
|
||||
|
||||
VOption *options = VImage::option()->set("access", "sequential");
|
||||
|
@ -63,5 +63,10 @@ char *Reddit(string type, string *outType, char *BufferData,
|
|||
? VImage::option()->set("dither", 0)->set("reoptimise", 1)
|
||||
: 0);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = width;
|
||||
output["height"] = pageHeight + watermark.height();
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Reddit(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Reddit(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -5,7 +5,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Resize(string type, string *outType, char *BufferData,
|
||||
ArgumentMap Resize(string type, string *outType, char *BufferData,
|
||||
size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
|
||||
bool stretch = GetArgumentWithFallback<bool>(Arguments, "stretch", false);
|
||||
bool wide = GetArgumentWithFallback<bool>(Arguments, "wide", false);
|
||||
|
@ -50,5 +50,10 @@ char *Resize(string type, string *outType, char *BufferData,
|
|||
void *buf;
|
||||
out.write_to_buffer(("." + *outType).c_str(), &buf, DataSize);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = width;
|
||||
output["height"] = finalHeight;
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Resize(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Resize(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -6,7 +6,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Reverse(string type, string *outType, char *BufferData,
|
||||
ArgumentMap Reverse(string type, string *outType, char *BufferData,
|
||||
size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
|
||||
bool soos = GetArgumentWithFallback<bool>(Arguments, "soos", false);
|
||||
|
||||
|
@ -55,5 +55,10 @@ char *Reverse(string type, string *outType, char *BufferData,
|
|||
|
||||
*outType = "gif";
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = width;
|
||||
output["height"] = pageHeight;
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Reverse(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Reverse(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -5,7 +5,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Scott(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Scott(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t *DataSize) {
|
||||
string basePath = GetArgument<string>(Arguments, "basePath");
|
||||
|
||||
|
@ -51,5 +51,11 @@ char *Scott(string type, string *outType, char *BufferData, size_t BufferLength,
|
|||
final.write_to_buffer(
|
||||
("." + *outType).c_str(), &buf, DataSize,
|
||||
*outType == "gif" ? VImage::option()->set("dither", 1) : 0);
|
||||
return (char *)buf;
|
||||
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = width;
|
||||
output["height"] = pageHeight;
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Scott(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Scott(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -5,7 +5,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Snapchat(string type, string *outType, char *BufferData,
|
||||
ArgumentMap Snapchat(string type, string *outType, char *BufferData,
|
||||
size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
|
||||
string caption = GetArgument<string>(Arguments, "caption");
|
||||
float pos = GetArgumentWithFallback<float>(Arguments, "pos", 0.5);
|
||||
|
@ -68,5 +68,10 @@ char *Snapchat(string type, string *outType, char *BufferData,
|
|||
? VImage::option()->set("dither", 0)->set("reoptimise", 1)
|
||||
: 0);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = width;
|
||||
output["height"] = pageHeight;
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Snapchat(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Snapchat(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -5,7 +5,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Sonic(string type, string *outType, ArgumentMap Arguments,
|
||||
ArgumentMap Sonic(string type, string *outType, ArgumentMap Arguments,
|
||||
size_t *DataSize) {
|
||||
string text = GetArgument<string>(Arguments, "text");
|
||||
string basePath = GetArgument<string>(Arguments, "basePath");
|
||||
|
@ -31,5 +31,10 @@ char *Sonic(string type, string *outType, ArgumentMap Arguments,
|
|||
void *buf;
|
||||
out.write_to_buffer(("." + *outType).c_str(), &buf, DataSize);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = out.width();
|
||||
output["height"] = vips_image_get_page_height(out.get_image());
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,4 +4,4 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char *Sonic(string type, string *outType, ArgumentMap Arguments, size_t *DataSize);
|
||||
ArgumentMap Sonic(string type, string *outType, ArgumentMap Arguments, size_t *DataSize);
|
|
@ -14,7 +14,7 @@ void *memset16(void *m, uint16_t val, size_t count) {
|
|||
return m;
|
||||
}
|
||||
|
||||
char *vipsRemove(char *data, size_t length, size_t *DataSize, int speed) {
|
||||
ArgumentMap vipsHandle(char *data, size_t length, size_t *DataSize, int speed, bool removeFrames) {
|
||||
VOption *options = VImage::option()->set("access", "sequential");
|
||||
|
||||
VImage in = VImage::new_from_buffer(data, length, "", options->set("n", -1))
|
||||
|
@ -25,21 +25,31 @@ char *vipsRemove(char *data, size_t length, size_t *DataSize, int speed) {
|
|||
int pageHeight = vips_image_get_page_height(in.get_image());
|
||||
int nPages = vips_image_get_n_pages(in.get_image());
|
||||
|
||||
VImage out;
|
||||
if (removeFrames) {
|
||||
vector<VImage> img;
|
||||
for (int i = 0; i < nPages; i += speed) {
|
||||
VImage img_frame = in.crop(0, i * pageHeight, width, pageHeight);
|
||||
img.push_back(img_frame);
|
||||
}
|
||||
VImage out = VImage::arrayjoin(img, VImage::option()->set("across", 1));
|
||||
out = VImage::arrayjoin(img, VImage::option()->set("across", 1));
|
||||
out.set(VIPS_META_PAGE_HEIGHT, pageHeight);
|
||||
} else {
|
||||
out = in;
|
||||
}
|
||||
|
||||
void *buf;
|
||||
out.write_to_buffer(".gif", &buf, DataSize);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = width;
|
||||
output["height"] = pageHeight;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
char *Speed([[maybe_unused]] string type, string *outType, char *BufferData,
|
||||
ArgumentMap Speed([[maybe_unused]] string type, string *outType, char *BufferData,
|
||||
size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
|
||||
bool slow = GetArgumentWithFallback<bool>(Arguments, "slow", false);
|
||||
int speed = GetArgumentWithFallback<int>(Arguments, "speed", 2);
|
||||
|
@ -92,11 +102,8 @@ char *Speed([[maybe_unused]] string type, string *outType, char *BufferData,
|
|||
++currentFrame;
|
||||
}
|
||||
|
||||
if (removeFrames) {
|
||||
fileData = vipsRemove(BufferData, BufferLength, DataSize, speed);
|
||||
} else {
|
||||
*DataSize = BufferLength;
|
||||
}
|
||||
// TODO: this is cursed, fix it later
|
||||
ArgumentMap output = vipsHandle(BufferData, BufferLength, DataSize, speed, removeFrames);
|
||||
|
||||
return fileData;
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Speed(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Speed(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -9,7 +9,7 @@
|
|||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
char *Spin(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Spin(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
[[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) {
|
||||
int delay = GetArgumentWithFallback<int>(Arguments, "delay", 0);
|
||||
|
||||
|
@ -68,5 +68,11 @@ char *Spin(string type, string *outType, char *BufferData, size_t BufferLength,
|
|||
|
||||
char *data = (char *)malloc(*DataSize);
|
||||
memcpy(data, blob.data(), *DataSize);
|
||||
return data;
|
||||
|
||||
ArgumentMap output;
|
||||
output["buf"] = data;
|
||||
output["width"] = (int)mid.front().columns();
|
||||
output["height"] = (int)mid.front().rows();
|
||||
|
||||
return output;
|
||||
}
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Spin(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Spin(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -7,7 +7,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Squish(string type, string *outType, char *BufferData,
|
||||
ArgumentMap Squish(string type, string *outType, char *BufferData,
|
||||
size_t BufferLength, [[maybe_unused]] ArgumentMap Arguments,
|
||||
size_t *DataSize) {
|
||||
VOption *options = VImage::option();
|
||||
|
@ -48,5 +48,10 @@ char *Squish(string type, string *outType, char *BufferData,
|
|||
|
||||
*outType = "gif";
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = final.width();
|
||||
output["height"] = vips_image_get_page_height(final.get_image());
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Squish(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Squish(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -5,7 +5,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Swirl(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Swirl(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
[[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) {
|
||||
VOption *options = VImage::option()->set("access", "sequential");
|
||||
|
||||
|
@ -72,5 +72,10 @@ char *Swirl(string type, string *outType, char *BufferData, size_t BufferLength,
|
|||
void *buf;
|
||||
final.write_to_buffer(("." + *outType).c_str(), &buf, DataSize);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = final.width();
|
||||
output["height"] = vips_image_get_page_height(final.get_image());
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Swirl(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Swirl(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -9,7 +9,7 @@
|
|||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
char *Tile(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Tile(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
[[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) {
|
||||
Blob blob;
|
||||
|
||||
|
@ -61,5 +61,11 @@ char *Tile(string type, string *outType, char *BufferData, size_t BufferLength,
|
|||
|
||||
char *data = (char *)malloc(*DataSize);
|
||||
memcpy(data, blob.data(), *DataSize);
|
||||
return data;
|
||||
|
||||
ArgumentMap output;
|
||||
output["buf"] = data;
|
||||
output["width"] = (int)mid.front().columns();
|
||||
output["height"] = (int)mid.front().rows();
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Tile(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Tile(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -5,13 +5,18 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *ToGif(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap ToGif(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
[[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) {
|
||||
if (type == "gif") {
|
||||
*DataSize = BufferLength;
|
||||
char *data = (char *)malloc(BufferLength);
|
||||
memcpy(data, BufferData, BufferLength);
|
||||
return data;
|
||||
|
||||
ArgumentMap output;
|
||||
output["buf"] = data;
|
||||
|
||||
return output;
|
||||
|
||||
} else {
|
||||
VOption *options = VImage::option()->set("access", "sequential");
|
||||
|
||||
|
@ -23,6 +28,11 @@ char *ToGif(string type, string *outType, char *BufferData, size_t BufferLength,
|
|||
in.write_to_buffer(".gif", &buf, DataSize);
|
||||
*outType = "gif";
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = in.width();
|
||||
output["height"] = vips_image_get_page_height(in.get_image());
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* ToGif(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap ToGif(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -5,7 +5,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Uncanny(string type, string *outType, char *BufferData,
|
||||
ArgumentMap Uncanny(string type, string *outType, char *BufferData,
|
||||
size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
|
||||
string caption = GetArgument<string>(Arguments, "caption");
|
||||
string caption2 = GetArgument<string>(Arguments, "caption2");
|
||||
|
@ -97,5 +97,10 @@ char *Uncanny(string type, string *outType, char *BufferData,
|
|||
("." + *outType).c_str(), &buf, DataSize,
|
||||
*outType == "gif" ? VImage::option()->set("reoptimise", 1) : 0);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = final.width();
|
||||
output["height"] = vips_image_get_page_height(final.get_image());
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Uncanny(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Uncanny(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -6,7 +6,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Uncaption(string type, string *outType, char *BufferData,
|
||||
ArgumentMap Uncaption(string type, string *outType, char *BufferData,
|
||||
size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
|
||||
float tolerance = GetArgumentWithFallback<float>(Arguments, "tolerance", 0.5);
|
||||
|
||||
|
@ -50,5 +50,10 @@ char *Uncaption(string type, string *outType, char *BufferData,
|
|||
? VImage::option()->set("dither", 0)->set("reoptimise", 1)
|
||||
: 0);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = final.width();
|
||||
output["height"] = vips_image_get_page_height(final.get_image());
|
||||
|
||||
return output;
|
||||
}
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Uncaption(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Uncaption(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -9,7 +9,7 @@
|
|||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
char *Wall(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Wall(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
[[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) {
|
||||
Blob blob;
|
||||
|
||||
|
@ -54,5 +54,11 @@ char *Wall(string type, string *outType, char *BufferData, size_t BufferLength,
|
|||
|
||||
char *data = (char *)malloc(*DataSize);
|
||||
memcpy(data, blob.data(), *DataSize);
|
||||
return data;
|
||||
|
||||
ArgumentMap output;
|
||||
output["buf"] = data;
|
||||
output["width"] = (int)mid.front().columns();
|
||||
output["height"] = (int)mid.front().rows();
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Wall(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Wall(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -6,7 +6,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Watermark(string type, string *outType, char *BufferData,
|
||||
ArgumentMap Watermark(string type, string *outType, char *BufferData,
|
||||
size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
|
||||
string water = GetArgument<string>(Arguments, "water");
|
||||
int gravity = GetArgument<int>(Arguments, "gravity");
|
||||
|
@ -150,5 +150,10 @@ char *Watermark(string type, string *outType, char *BufferData,
|
|||
? VImage::option()->set("dither", 0)->set("reoptimise", 1)
|
||||
: 0);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = final.width();
|
||||
output["height"] = vips_image_get_page_height(final.get_image());
|
||||
|
||||
return output;
|
||||
}
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Watermark(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Watermark(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -5,7 +5,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Whisper(string type, string *outType, char *BufferData,
|
||||
ArgumentMap Whisper(string type, string *outType, char *BufferData,
|
||||
size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
|
||||
string caption = GetArgument<string>(Arguments, "caption");
|
||||
string basePath = GetArgument<string>(Arguments, "basePath");
|
||||
|
@ -82,5 +82,10 @@ char *Whisper(string type, string *outType, char *BufferData,
|
|||
? VImage::option()->set("dither", 0)->set("reoptimise", 1)
|
||||
: 0);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = width;
|
||||
output["height"] = pageHeight;
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Whisper(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Whisper(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -5,7 +5,7 @@
|
|||
using namespace std;
|
||||
using namespace vips;
|
||||
|
||||
char *Zamn(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Zamn(string type, string *outType, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t *DataSize) {
|
||||
string basePath = GetArgument<string>(Arguments, "basePath");
|
||||
|
||||
|
@ -43,5 +43,10 @@ char *Zamn(string type, string *outType, char *BufferData, size_t BufferLength,
|
|||
void *buf;
|
||||
final.write_to_buffer(("." + *outType).c_str(), &buf, DataSize);
|
||||
|
||||
return (char *)buf;
|
||||
ArgumentMap output;
|
||||
output["buf"] = (char *)buf;
|
||||
output["width"] = final.width();
|
||||
output["height"] = vips_image_get_page_height(final.get_image());
|
||||
|
||||
return output;
|
||||
}
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
char* Zamn(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Zamn(string type, string* outType, char* BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t* DataSize);
|
|
@ -50,7 +50,9 @@ export default function run(object) {
|
|||
const result = img.image(object.cmd, objectWithFixedType);
|
||||
const returnObject = {
|
||||
buffer: result.data,
|
||||
fileExtension: result.type
|
||||
fileExtension: result.type,
|
||||
width: result.width,
|
||||
height: result.height
|
||||
};
|
||||
resolve(returnObject);
|
||||
} catch (e) {
|
||||
|
|
|
@ -135,7 +135,9 @@ function waitForWorker(worker) {
|
|||
worker.once("message", (data) => {
|
||||
resolve({
|
||||
buffer: Buffer.from([...data.buffer]),
|
||||
type: data.fileExtension
|
||||
type: data.fileExtension,
|
||||
width: data.width,
|
||||
height: data.height
|
||||
});
|
||||
});
|
||||
worker.once("error", reject);
|
||||
|
|
Loading…
Reference in a new issue