A few tweaks

This commit is contained in:
Essem 2022-06-20 01:05:06 -05:00
parent 598c29ab17
commit 34c0ee14e0
No known key found for this signature in database
GPG Key ID: 7D497397CC3A2A8C
22 changed files with 154 additions and 105 deletions

View File

@ -24,7 +24,7 @@ Napi::Value Caption(const Napi::CallbackInfo &info) {
int width = in.width();
int size = width / 10;
int page_height = vips_image_get_page_height(in.get_image());
int pageHeight = vips_image_get_page_height(in.get_image());
int n_pages = vips_image_get_n_pages(in.get_image());
int textWidth = width - ((width / 25) * 2);
@ -49,14 +49,14 @@ Napi::Value Caption(const Napi::CallbackInfo &info) {
vector<VImage> img;
for (int i = 0; i < n_pages; i++) {
VImage img_frame =
type == "gif" ? in.crop(0, i * page_height, width, page_height) : in;
type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
VImage frame = captionImage.join(
img_frame, VIPS_DIRECTION_VERTICAL,
VImage::option()->set("background", 0xffffff)->set("expand", true));
img.push_back(frame);
}
VImage final = VImage::arrayjoin(img, VImage::option()->set("across", 1));
final.set(VIPS_META_PAGE_HEIGHT, page_height + captionImage.height());
final.set(VIPS_META_PAGE_HEIGHT, pageHeight + captionImage.height());
void *buf;
size_t length;

View File

@ -26,7 +26,7 @@ Napi::Value CaptionTwo(const Napi::CallbackInfo &info) {
int width = in.width();
int size = width / 13;
int page_height = vips_image_get_page_height(in.get_image());
int pageHeight = vips_image_get_page_height(in.get_image());
int n_pages = vips_image_get_n_pages(in.get_image());
int textWidth = width - ((width / 25) * 2);
@ -50,7 +50,7 @@ Napi::Value CaptionTwo(const Napi::CallbackInfo &info) {
vector<VImage> img;
for (int i = 0; i < n_pages; i++) {
VImage img_frame =
type == "gif" ? in.crop(0, i * page_height, width, page_height) : in;
type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
VImage frame =
(top ? captionImage : img_frame)
.join(top ? img_frame : captionImage, VIPS_DIRECTION_VERTICAL,
@ -60,7 +60,7 @@ Napi::Value CaptionTwo(const Napi::CallbackInfo &info) {
img.push_back(frame);
}
VImage final = VImage::arrayjoin(img, VImage::option()->set("across", 1));
final.set(VIPS_META_PAGE_HEIGHT, page_height + captionImage.height());
final.set(VIPS_META_PAGE_HEIGHT, pageHeight + captionImage.height());
void *buf;
size_t length;

View File

@ -21,14 +21,14 @@ Napi::Value Crop(const Napi::CallbackInfo &info) {
.colourspace(VIPS_INTERPRETATION_sRGB);
int width = in.width();
int page_height = vips_image_get_page_height(in.get_image());
int pageHeight = vips_image_get_page_height(in.get_image());
int n_pages = vips_image_get_n_pages(in.get_image());
vector<VImage> img;
int finalHeight = 0;
for (int i = 0; i < n_pages; i++) {
VImage img_frame =
type == "gif" ? in.crop(0, i * page_height, width, page_height) : in;
type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
int frameWidth = img_frame.width();
int frameHeight = img_frame.height();
bool widthOrHeight = frameWidth / frameHeight >= 1;

View File

@ -21,24 +21,49 @@ Napi::Value Deepfry(const Napi::CallbackInfo &info) {
VImage::new_from_buffer(data.Data(), data.Length(), "",
type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha()) in = in.bandjoin(255);
if (!in.has_alpha())
in = in.bandjoin(255);
int page_height = vips_image_get_page_height(in.get_image());
int width = in.width();
int pageHeight = vips_image_get_page_height(in.get_image());
int totalHeight = in.height();
int n_pages = vips_image_get_n_pages(in.get_image());
VImage fried = (in * 1.3 - (255.0 * 1.3 - 255.0)) * 1.5;
void *jpgBuf;
size_t jpgLength;
fried.write_to_buffer(".jpg", &jpgBuf, &jpgLength,
VImage::option()->set("Q", 1)->set("strip", true));
VImage final = VImage::new_from_buffer(jpgBuf, jpgLength, "");
final.set(VIPS_META_PAGE_HEIGHT, page_height);
if (type == "gif") final.set("delay", fried.get_array_int("delay"));
VImage final;
if (totalHeight > 65500 && type == "gif") {
vector<VImage> img;
for (int i = 0; i < n_pages; i++) {
VImage img_frame = in.crop(0, i * pageHeight, width, pageHeight);
void *jpgBuf;
size_t jpgLength;
img_frame.write_to_buffer(
".jpg", &jpgBuf, &jpgLength,
VImage::option()->set("Q", 1)->set("strip", true));
VImage jpeged = VImage::new_from_buffer(jpgBuf, jpgLength, "");
jpeged.set(VIPS_META_PAGE_HEIGHT, pageHeight);
jpeged.set("delay", in.get_array_int("delay"));
img.push_back(jpeged);
}
final = VImage::arrayjoin(img, VImage::option()->set("across", 1));
final.set(VIPS_META_PAGE_HEIGHT, pageHeight);
} else {
void *jpgBuf;
size_t jpgLength;
fried.write_to_buffer(".jpg", &jpgBuf, &jpgLength,
VImage::option()->set("Q", 1)->set("strip", true));
final = VImage::new_from_buffer(jpgBuf, jpgLength, "");
final.set(VIPS_META_PAGE_HEIGHT, pageHeight);
if (type == "gif")
final.set("delay", fried.get_array_int("delay"));
}
void *buf;
size_t length;
final.write_to_buffer(
("." + type).c_str(), &buf, &length,
type == "gif" ? VImage::option()->set("dither", 0) : 0);
final.write_to_buffer(("." + type).c_str(), &buf, &length,
type == "gif" ? VImage::option()->set("dither", 0)
: 0);
vips_thread_shutdown();

View File

@ -24,7 +24,7 @@ Napi::Value Flag(const Napi::CallbackInfo &info) {
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int page_height = vips_image_get_page_height(in.get_image());
int pageHeight = vips_image_get_page_height(in.get_image());
int n_pages = vips_image_get_n_pages(in.get_image());
string assetPath = basePath + overlay;
@ -32,7 +32,7 @@ Napi::Value Flag(const Napi::CallbackInfo &info) {
VImage overlayImage = overlayInput.resize(
(double)width / (double)overlayInput.width(),
VImage::option()->set(
"vscale", (double)page_height / (double)overlayInput.height()));
"vscale", (double)pageHeight / (double)overlayInput.height()));
if (!overlayImage.has_alpha()) {
overlayImage = overlayImage.bandjoin(127);
} else {
@ -43,14 +43,14 @@ Napi::Value Flag(const Napi::CallbackInfo &info) {
vector<VImage> img;
for (int i = 0; i < n_pages; i++) {
VImage img_frame =
type == "gif" ? in.crop(0, i * page_height, width, page_height) : in;
type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
VImage composited =
img_frame.composite2(overlayImage, VIPS_BLEND_MODE_OVER);
img.push_back(composited);
}
VImage final = VImage::arrayjoin(img, VImage::option()->set("across", 1));
final.set(VIPS_META_PAGE_HEIGHT, page_height);
final.set(VIPS_META_PAGE_HEIGHT, pageHeight);
void *buf;
size_t length;

View File

@ -29,15 +29,15 @@ Napi::Value Flip(const Napi::CallbackInfo &info) {
} else if (type == "gif") {
// libvips gif handling is both a blessing and a curse
vector<VImage> img;
int page_height = vips_image_get_page_height(in.get_image());
int pageHeight = vips_image_get_page_height(in.get_image());
int n_pages = vips_image_get_n_pages(in.get_image());
for (int i = 0; i < n_pages; i++) {
VImage img_frame = in.crop(0, i * page_height, in.width(), page_height);
VImage img_frame = in.crop(0, i * pageHeight, in.width(), pageHeight);
VImage flipped = img_frame.flip(VIPS_DIRECTION_VERTICAL);
img.push_back(flipped);
}
out = VImage::arrayjoin(img, VImage::option()->set("across", 1));
out.set(VIPS_META_PAGE_HEIGHT, page_height);
out.set(VIPS_META_PAGE_HEIGHT, pageHeight);
} else {
out = in.flip(VIPS_DIRECTION_VERTICAL);
}

View File

@ -58,11 +58,11 @@ Napi::Value Freeze(const Napi::CallbackInfo &info) {
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha()) in = in.bandjoin(255);
int page_height = vips_image_get_page_height(in.get_image());
int pageHeight = vips_image_get_page_height(in.get_image());
int n_pages = vips_image_get_n_pages(in.get_image());
int framePos = clamp(frame, 0, (int)n_pages);
VImage out = in.crop(0, 0, in.width(), page_height * (framePos + 1));
out.set(VIPS_META_PAGE_HEIGHT, page_height);
VImage out = in.crop(0, 0, in.width(), pageHeight * (framePos + 1));
out.set(VIPS_META_PAGE_HEIGHT, pageHeight);
out.set("loop", loop ? 0 : 1);
void *buf;

View File

@ -26,17 +26,17 @@ Napi::Value Gamexplain(const Napi::CallbackInfo &info) {
VImage tmpl = VImage::new_from_file(assetPath.c_str());
int width = in.width();
int page_height = vips_image_get_page_height(in.get_image());
int pageHeight = vips_image_get_page_height(in.get_image());
int n_pages = vips_image_get_n_pages(in.get_image());
vector<VImage> img;
for (int i = 0; i < n_pages; i++) {
VImage img_frame =
type == "gif" ? in.crop(0, i * page_height, width, page_height) : in;
type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
VImage resized = img_frame
.resize(1181.0 / (double)width,
VImage::option()->set(
"vscale", 571.0 / (double)page_height))
"vscale", 571.0 / (double)pageHeight))
.embed(10, 92, 1200, 675,
VImage::option()->set("extend", "white"));
VImage composited = resized.composite2(tmpl, VIPS_BLEND_MODE_OVER);

View File

@ -25,10 +25,10 @@ Napi::Value Globe(const Napi::CallbackInfo &info) {
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int page_height = vips_image_get_page_height(in.get_image());
int pageHeight = vips_image_get_page_height(in.get_image());
int n_pages = type == "gif" ? vips_image_get_n_pages(in.get_image()) : 30;
double size = min(width, page_height);
double size = min(width, pageHeight);
string diffPath = basePath + "assets/images/globediffuse.png";
VImage diffuse =
@ -54,10 +54,10 @@ Napi::Value Globe(const Napi::CallbackInfo &info) {
vector<VImage> img;
for (int i = 0; i < n_pages; i++) {
VImage img_frame =
type == "gif" ? in.crop(0, i * page_height, width, page_height) : in;
type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
VImage resized = img_frame.resize(
size / (double)width,
VImage::option()->set("vscale", size / (double)page_height));
VImage::option()->set("vscale", size / (double)pageHeight));
VImage rolled = img_frame.wrap(
VImage::option()->set("x", width * i / n_pages)->set("y", 0));
VImage extracted = rolled.extract_band(0, VImage::option()->set("n", 3));

View File

@ -24,24 +24,48 @@ Napi::Value Jpeg(const Napi::CallbackInfo &info) {
data.Data(), data.Length(), "",
VImage::option()->set("access", "sequential")->set("n", -1))
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha()) in = in.bandjoin(255);
if (!in.has_alpha())
in = in.bandjoin(255);
int page_height = vips_image_get_page_height(in.get_image());
int width = in.width();
int pageHeight = vips_image_get_page_height(in.get_image());
int totalHeight = in.height();
int n_pages = vips_image_get_n_pages(in.get_image());
void *jpgBuf;
size_t jpgLength;
in.write_to_buffer(
".jpg", &jpgBuf, &jpgLength,
VImage::option()->set("Q", quality)->set("strip", true));
VImage final = VImage::new_from_buffer(jpgBuf, jpgLength, "");
final.set(VIPS_META_PAGE_HEIGHT, page_height);
if (type == "gif") final.set("delay", in.get_array_int("delay"));
VImage final;
if (totalHeight > 65500) {
vector<VImage> img;
for (int i = 0; i < n_pages; i++) {
VImage img_frame = in.crop(0, i * pageHeight, width, pageHeight);
void *jpgBuf;
size_t jpgLength;
img_frame.write_to_buffer(
".jpg", &jpgBuf, &jpgLength,
VImage::option()->set("Q", quality)->set("strip", true));
VImage jpeged = VImage::new_from_buffer(jpgBuf, jpgLength, "");
jpeged.set(VIPS_META_PAGE_HEIGHT, pageHeight);
jpeged.set("delay", in.get_array_int("delay"));
img.push_back(jpeged);
}
final = VImage::arrayjoin(img, VImage::option()->set("across", 1));
final.set(VIPS_META_PAGE_HEIGHT, pageHeight);
} else {
void *jpgBuf;
size_t jpgLength;
in.write_to_buffer(
".jpg", &jpgBuf, &jpgLength,
VImage::option()->set("Q", quality)->set("strip", true));
final = VImage::new_from_buffer(jpgBuf, jpgLength, "");
final.set(VIPS_META_PAGE_HEIGHT, pageHeight);
final.set("delay", in.get_array_int("delay"));
}
void *buf;
size_t length;
final.write_to_buffer(
("." + type).c_str(), &buf, &length,
type == "gif" ? VImage::option()->set("dither", 0) : 0);
final.write_to_buffer(("." + type).c_str(), &buf, &length,
type == "gif" ? VImage::option()->set("dither", 0)
: 0);
vips_thread_shutdown();

View File

@ -25,7 +25,7 @@ Napi::Value Meme(const Napi::CallbackInfo &info) {
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int page_height = vips_image_get_page_height(in.get_image());
int pageHeight = vips_image_get_page_height(in.get_image());
int n_pages = vips_image_get_n_pages(in.get_image());
int size = width / 9;
int dividedWidth = width / 1000;
@ -106,7 +106,7 @@ Napi::Value Meme(const Napi::CallbackInfo &info) {
vector<VImage> img;
for (int i = 0; i < n_pages; i++) {
VImage img_frame =
type == "gif" ? in.crop(0, i * page_height, width, page_height) : in;
type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
if (top != "") {
img_frame = img_frame.composite2(
topText, VIPS_BLEND_MODE_OVER,
@ -117,12 +117,12 @@ Napi::Value Meme(const Napi::CallbackInfo &info) {
bottomText, VIPS_BLEND_MODE_OVER,
VImage::option()
->set("x", (width / 2) - (bottomText.width() / 2))
->set("y", page_height - bottomText.height()));
->set("y", pageHeight - bottomText.height()));
}
img.push_back(img_frame);
}
VImage final = VImage::arrayjoin(img, VImage::option()->set("across", 1));
final.set(VIPS_META_PAGE_HEIGHT, page_height);
final.set(VIPS_META_PAGE_HEIGHT, pageHeight);
void *buf;
size_t length;

View File

@ -32,12 +32,12 @@ Napi::Value Mirror(const Napi::CallbackInfo &info) {
if (type == "gif") {
// once again, libvips gif handling is both a blessing and a curse
vector<VImage> img;
int page_height = vips_image_get_page_height(in.get_image());
int pageHeight = vips_image_get_page_height(in.get_image());
int n_pages = vips_image_get_n_pages(in.get_image());
bool isOdd = page_height % 2;
bool isOdd = pageHeight % 2;
for (int i = 0; i < n_pages; i++) {
int x = (i * page_height) + (first ? 0 : (page_height / 2));
VImage cropped = in.crop(0, x, in.width(), page_height / 2);
int x = (i * pageHeight) + (first ? 0 : (pageHeight / 2));
VImage cropped = in.crop(0, x, in.width(), pageHeight / 2);
VImage flipped = cropped.flip(VIPS_DIRECTION_VERTICAL);
VImage final = VImage::arrayjoin(
{first ? cropped : flipped, first ? flipped : cropped},
@ -45,7 +45,7 @@ Napi::Value Mirror(const Napi::CallbackInfo &info) {
img.push_back(final);
}
out = VImage::arrayjoin(img, VImage::option()->set("across", 1));
out.set(VIPS_META_PAGE_HEIGHT, page_height - (isOdd ? 1 : 0));
out.set(VIPS_META_PAGE_HEIGHT, pageHeight - (isOdd ? 1 : 0));
} else {
VImage cropped = in.extract_area(0, 0, in.width(), in.height() / 2);
VImage flipped = cropped.flip(VIPS_DIRECTION_VERTICAL);

View File

@ -26,7 +26,7 @@ Napi::Value Motivate(const Napi::CallbackInfo &info) {
int width = in.width();
int size = width / 5;
int page_height = vips_image_get_page_height(in.get_image());
int pageHeight = vips_image_get_page_height(in.get_image());
int n_pages = vips_image_get_n_pages(in.get_image());
int textWidth = width - ((width / 25) * 2);
@ -61,13 +61,13 @@ Napi::Value Motivate(const Napi::CallbackInfo &info) {
int height;
for (int i = 0; i < n_pages; i++) {
VImage img_frame =
type == "gif" ? in.crop(0, i * page_height, width, page_height) : in;
type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
int borderSize = max(2, width / 66);
int borderSize2 = borderSize * 0.5;
VImage bordered =
img_frame.embed(borderSize, borderSize, width + (borderSize * 2),
page_height + (borderSize * 2),
pageHeight + (borderSize * 2),
VImage::option()->set("extend", "black"));
VImage bordered2 = bordered.embed(
borderSize2, borderSize2, bordered.width() + (borderSize2 * 2),
@ -75,7 +75,7 @@ Napi::Value Motivate(const Napi::CallbackInfo &info) {
VImage::option()->set("extend", "white"));
int addition = width / 8;
int sideAddition = page_height * 0.4;
int sideAddition = pageHeight * 0.4;
VImage bordered3 = bordered2.embed(
sideAddition / 2, addition / 2, bordered2.width() + sideAddition,

View File

@ -26,7 +26,7 @@ Napi::Value Reddit(const Napi::CallbackInfo &info) {
VImage tmpl = VImage::new_from_file(assetPath.c_str());
int width = in.width();
int page_height = vips_image_get_page_height(in.get_image());
int pageHeight = vips_image_get_page_height(in.get_image());
int n_pages = vips_image_get_n_pages(in.get_image());
string captionText = "<span foreground=\"white\">" + text + "</span>";
@ -47,13 +47,13 @@ Napi::Value Reddit(const Napi::CallbackInfo &info) {
vector<VImage> img;
for (int i = 0; i < n_pages; i++) {
VImage img_frame =
type == "gif" ? in.crop(0, i * page_height, width, page_height) : in;
type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
VImage frame = img_frame.join(watermark, VIPS_DIRECTION_VERTICAL,
VImage::option()->set("expand", true));
img.push_back(frame);
}
VImage final = VImage::arrayjoin(img, VImage::option()->set("across", 1));
final.set(VIPS_META_PAGE_HEIGHT, page_height + watermark.height());
final.set(VIPS_META_PAGE_HEIGHT, pageHeight + watermark.height());
void *buf;
size_t length;

View File

@ -28,21 +28,21 @@ Napi::Value Resize(const Napi::CallbackInfo &info) {
VImage out;
int width = in.width();
int page_height = vips_image_get_page_height(in.get_image());
int pageHeight = vips_image_get_page_height(in.get_image());
int finalHeight;
if (stretch) {
out = in.resize(
512.0 / (double)width,
VImage::option()->set("vscale", 512.0 / (double)page_height));
VImage::option()->set("vscale", 512.0 / (double)pageHeight));
finalHeight = 512;
} else if (wide) {
out = in.resize(9.5, VImage::option()->set("vscale", 0.5));
finalHeight = page_height / 2;
finalHeight = pageHeight / 2;
} else {
out = in.resize(0.1).resize(
10, VImage::option()->set("kernel", VIPS_KERNEL_NEAREST));
finalHeight = page_height;
finalHeight = pageHeight;
}
out.set(VIPS_META_PAGE_HEIGHT, finalHeight);

View File

@ -21,13 +21,13 @@ Napi::Value Reverse(const Napi::CallbackInfo &info) {
.colourspace(VIPS_INTERPRETATION_sRGB);
int width = in.width();
int page_height = vips_image_get_page_height(in.get_image());
int pageHeight = vips_image_get_page_height(in.get_image());
int n_pages = vips_image_get_n_pages(in.get_image());
vector<VImage> split;
// todo: find a better way of getting individual frames (or at least getting the frames in reverse order)
for (int i = 0; i < n_pages; i++) {
VImage img_frame = in.crop(0, i * page_height, width, page_height);
VImage img_frame = in.crop(0, i * pageHeight, width, pageHeight);
split.push_back(img_frame);
}
@ -49,7 +49,7 @@ Napi::Value Reverse(const Napi::CallbackInfo &info) {
}
VImage final = VImage::arrayjoin(split, VImage::option()->set("across", 1));
final.set(VIPS_META_PAGE_HEIGHT, page_height);
final.set(VIPS_META_PAGE_HEIGHT, pageHeight);
final.set("delay", delays);
void *buf;

View File

@ -25,7 +25,7 @@ Napi::Value Snapchat(const Napi::CallbackInfo &info) {
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int page_height = vips_image_get_page_height(in.get_image());
int pageHeight = vips_image_get_page_height(in.get_image());
int n_pages = vips_image_get_n_pages(in.get_image());
int size = width / 20;
int textWidth = width - ((width / 25) * 2);
@ -54,14 +54,14 @@ Napi::Value Snapchat(const Napi::CallbackInfo &info) {
vector<VImage> img;
for (int i = 0; i < n_pages; i++) {
VImage img_frame =
type == "gif" ? in.crop(0, i * page_height, width, page_height) : in;
type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
img_frame = img_frame.composite2(
textIn, VIPS_BLEND_MODE_OVER,
VImage::option()->set("x", 0)->set("y", page_height * pos));
VImage::option()->set("x", 0)->set("y", pageHeight * pos));
img.push_back(img_frame);
}
VImage final = VImage::arrayjoin(img, VImage::option()->set("across", 1));
final.set(VIPS_META_PAGE_HEIGHT, page_height);
final.set(VIPS_META_PAGE_HEIGHT, pageHeight);
void *buf;
size_t length;

View File

@ -22,16 +22,16 @@ void vipsRemove(Napi::Env *env, Napi::Object *result, Napi::Buffer<char> data,
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int page_height = vips_image_get_page_height(in.get_image());
int pageHeight = vips_image_get_page_height(in.get_image());
int n_pages = vips_image_get_n_pages(in.get_image());
vector<VImage> img;
for (int i = 0; i < n_pages; i += speed) {
VImage img_frame = in.crop(0, i * page_height, width, page_height);
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.set(VIPS_META_PAGE_HEIGHT, page_height);
out.set(VIPS_META_PAGE_HEIGHT, pageHeight);
void *buf;
size_t length;

View File

@ -25,24 +25,24 @@ Napi::Value Uncaption(const Napi::CallbackInfo &info) {
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int page_height = vips_image_get_page_height(in.get_image());
int pageHeight = vips_image_get_page_height(in.get_image());
int n_pages = vips_image_get_n_pages(in.get_image());
VImage first =
in.crop(0, 0, 3, page_height).colourspace(VIPS_INTERPRETATION_B_W) >
in.crop(0, 0, 3, pageHeight).colourspace(VIPS_INTERPRETATION_B_W) >
(255 * tolerance);
int top, captionWidth, captionHeight;
first.find_trim(&top, &captionWidth, &captionHeight);
vector<VImage> img;
int newHeight = page_height - top;
if (top == page_height) {
newHeight = page_height;
int newHeight = pageHeight - top;
if (top == pageHeight) {
newHeight = pageHeight;
top = 0;
}
for (int i = 0; i < n_pages; i++) {
VImage img_frame =
in.crop(0, (i * page_height) + top, width, newHeight);
in.crop(0, (i * pageHeight) + top, width, newHeight);
img.push_back(img_frame);
}
VImage final = VImage::arrayjoin(img, VImage::option()->set("across", 1));

View File

@ -40,7 +40,7 @@ Napi::Value Watermark(const Napi::CallbackInfo &info) {
VImage watermark = VImage::new_from_file(merged.c_str());
int width = in.width();
int page_height = vips_image_get_page_height(in.get_image());
int pageHeight = vips_image_get_page_height(in.get_image());
int n_pages = vips_image_get_n_pages(in.get_image());
if (resize && append) {
@ -48,11 +48,11 @@ Napi::Value Watermark(const Napi::CallbackInfo &info) {
} else if (resize && yscale) {
watermark = watermark.resize(
(double)width / (double)watermark.width(),
VImage::option()->set("vscale", (double)(page_height * yscale) /
VImage::option()->set("vscale", (double)(pageHeight * yscale) /
(double)watermark.height()));
} else if (resize) {
watermark =
watermark.resize((double)page_height / (double)watermark.height());
watermark.resize((double)pageHeight / (double)watermark.height());
}
int x = 0, y = 0;
@ -67,19 +67,19 @@ Napi::Value Watermark(const Napi::CallbackInfo &info) {
break;
case 5:
x = (width / 2) - (watermark.width() / 2);
y = (page_height / 2) - (watermark.height() / 2);
y = (pageHeight / 2) - (watermark.height() / 2);
break;
case 6:
x = width - watermark.width();
y = (page_height / 2) - (watermark.height() / 2);
y = (pageHeight / 2) - (watermark.height() / 2);
break;
case 8:
x = (width / 2) - (watermark.width() / 2);
y = page_height - watermark.height();
y = pageHeight - watermark.height();
break;
case 9:
x = width - watermark.width();
y = page_height - watermark.height();
y = pageHeight - watermark.height();
break;
}
@ -91,7 +91,7 @@ Napi::Value Watermark(const Napi::CallbackInfo &info) {
VImage frame;
for (int i = 0; i < n_pages; i++) {
VImage img_frame =
type == "gif" ? in.crop(0, i * page_height, width, page_height) : in;
type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
if (append) {
VImage appended = img_frame.join(watermark, VIPS_DIRECTION_VERTICAL,
VImage::option()->set("expand", true));
@ -99,7 +99,7 @@ Napi::Value Watermark(const Napi::CallbackInfo &info) {
img.push_back(appended);
} else if (mc) {
VImage padded =
img_frame.embed(0, 0, width, page_height + 15,
img_frame.embed(0, 0, width, pageHeight + 15,
VImage::option()->set("background", 0xffffff));
VImage composited =
padded.composite2(watermark, VIPS_BLEND_MODE_OVER,
@ -113,10 +113,10 @@ Napi::Value Watermark(const Napi::CallbackInfo &info) {
if (alpha) {
if (i == 0) {
contentAlpha = watermark.extract_band(0).embed(
x, y, width, page_height,
x, y, width, pageHeight,
VImage::option()->set("extend", "white"));
frameAlpha = watermark.extract_band(1).embed(
x, y, width, page_height,
x, y, width, pageHeight,
VImage::option()->set("extend", "black"));
bg =
frameAlpha.new_from_image({0, 0, 0}).copy(VImage::option()->set(
@ -142,7 +142,7 @@ Napi::Value Watermark(const Napi::CallbackInfo &info) {
}
}
VImage final = VImage::arrayjoin(img, VImage::option()->set("across", 1));
final.set(VIPS_META_PAGE_HEIGHT, page_height + addedHeight);
final.set(VIPS_META_PAGE_HEIGHT, pageHeight + addedHeight);
void *buf;
size_t length;

View File

@ -23,7 +23,7 @@ Napi::Value Whisper(const Napi::CallbackInfo &info) {
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int page_height = vips_image_get_page_height(in.get_image());
int pageHeight = vips_image_get_page_height(in.get_image());
int n_pages = vips_image_get_n_pages(in.get_image());
int size = width / 6;
int dividedWidth = width / 175;
@ -66,16 +66,16 @@ Napi::Value Whisper(const Napi::CallbackInfo &info) {
vector<VImage> img;
for (int i = 0; i < n_pages; i++) {
VImage img_frame =
type == "gif" ? in.crop(0, i * page_height, width, page_height) : in;
type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
img_frame = img_frame.composite2(
textImg, VIPS_BLEND_MODE_OVER,
VImage::option()
->set("x", (width / 2) - (textImg.width() / 2))
->set("y", (page_height / 2) - (textImg.height() / 2)));
->set("y", (pageHeight / 2) - (textImg.height() / 2)));
img.push_back(img_frame);
}
VImage final = VImage::arrayjoin(img, VImage::option()->set("across", 1));
final.set(VIPS_META_PAGE_HEIGHT, page_height);
final.set(VIPS_META_PAGE_HEIGHT, pageHeight);
void *buf;
size_t length;

View File

@ -23,7 +23,7 @@ Napi::Value Zamn(const Napi::CallbackInfo &info) {
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int page_height = vips_image_get_page_height(in.get_image());
int pageHeight = vips_image_get_page_height(in.get_image());
int n_pages = vips_image_get_n_pages(in.get_image());
string assetPath = basePath + "assets/images/zamn.png";
@ -32,11 +32,11 @@ Napi::Value Zamn(const Napi::CallbackInfo &info) {
vector<VImage> img;
for (int i = 0; i < n_pages; i++) {
VImage img_frame =
type == "gif" ? in.crop(0, i * page_height, width, page_height) : in;
type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
VImage composited = tmpl.insert(
img_frame.extract_band(0, VImage::option()->set("n", 3)).bandjoin(255).resize(
303.0 / (double)width,
VImage::option()->set("vscale", 438.0 / (double)page_height)),
VImage::option()->set("vscale", 438.0 / (double)pageHeight)),
310, 76);
img.push_back(composited);
}