From 34c0ee14e0f4af7b272389da60fbed6dec3330f1 Mon Sep 17 00:00:00 2001 From: Essem Date: Mon, 20 Jun 2022 01:05:06 -0500 Subject: [PATCH] A few tweaks --- natives/caption.cc | 6 +++--- natives/caption2.cc | 6 +++--- natives/crop.cc | 4 ++-- natives/deepfry.cc | 49 +++++++++++++++++++++++++++++++----------- natives/flag.cc | 8 +++---- natives/flip.cc | 6 +++--- natives/freeze.cc | 6 +++--- natives/gamexplain.cc | 6 +++--- natives/globe.cc | 8 +++---- natives/jpeg.cc | 50 ++++++++++++++++++++++++++++++++----------- natives/meme.cc | 8 +++---- natives/mirror.cc | 10 ++++----- natives/motivate.cc | 8 +++---- natives/reddit.cc | 6 +++--- natives/resize.cc | 8 +++---- natives/reverse.cc | 6 +++--- natives/snapchat.cc | 8 +++---- natives/speed.cc | 6 +++--- natives/uncaption.cc | 12 +++++------ natives/watermark.cc | 24 ++++++++++----------- natives/whisper.cc | 8 +++---- natives/zamn.cc | 6 +++--- 22 files changed, 154 insertions(+), 105 deletions(-) diff --git a/natives/caption.cc b/natives/caption.cc index 0521c31..fa45e27 100644 --- a/natives/caption.cc +++ b/natives/caption.cc @@ -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 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; diff --git a/natives/caption2.cc b/natives/caption2.cc index 4f6b83b..afc9051 100644 --- a/natives/caption2.cc +++ b/natives/caption2.cc @@ -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 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; diff --git a/natives/crop.cc b/natives/crop.cc index 0913969..260d76d 100644 --- a/natives/crop.cc +++ b/natives/crop.cc @@ -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 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; diff --git a/natives/deepfry.cc b/natives/deepfry.cc index f59fe23..5ea6db2 100644 --- a/natives/deepfry.cc +++ b/natives/deepfry.cc @@ -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 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(); diff --git a/natives/flag.cc b/natives/flag.cc index ddb2364..dd34eb1 100644 --- a/natives/flag.cc +++ b/natives/flag.cc @@ -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 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; diff --git a/natives/flip.cc b/natives/flip.cc index d572b47..7cffcb1 100644 --- a/natives/flip.cc +++ b/natives/flip.cc @@ -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 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); } diff --git a/natives/freeze.cc b/natives/freeze.cc index f7fe696..ac773bf 100644 --- a/natives/freeze.cc +++ b/natives/freeze.cc @@ -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; diff --git a/natives/gamexplain.cc b/natives/gamexplain.cc index b1a2671..6f8d25a 100644 --- a/natives/gamexplain.cc +++ b/natives/gamexplain.cc @@ -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 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); diff --git a/natives/globe.cc b/natives/globe.cc index 5997f16..06fc9ad 100644 --- a/natives/globe.cc +++ b/natives/globe.cc @@ -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 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)); diff --git a/natives/jpeg.cc b/natives/jpeg.cc index 512baf2..d3484d6 100644 --- a/natives/jpeg.cc +++ b/natives/jpeg.cc @@ -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 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(); diff --git a/natives/meme.cc b/natives/meme.cc index 409f599..606ca8d 100644 --- a/natives/meme.cc +++ b/natives/meme.cc @@ -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 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; diff --git a/natives/mirror.cc b/natives/mirror.cc index 0a4f896..a82b8f0 100644 --- a/natives/mirror.cc +++ b/natives/mirror.cc @@ -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 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); diff --git a/natives/motivate.cc b/natives/motivate.cc index 874ec72..388abd0 100644 --- a/natives/motivate.cc +++ b/natives/motivate.cc @@ -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, diff --git a/natives/reddit.cc b/natives/reddit.cc index 054c22a..f319a5b 100644 --- a/natives/reddit.cc +++ b/natives/reddit.cc @@ -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 = "" + text + ""; @@ -47,13 +47,13 @@ Napi::Value Reddit(const Napi::CallbackInfo &info) { vector 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; diff --git a/natives/resize.cc b/natives/resize.cc index 0e8f5ec..78716d9 100644 --- a/natives/resize.cc +++ b/natives/resize.cc @@ -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); diff --git a/natives/reverse.cc b/natives/reverse.cc index 1ebb6f8..05525d4 100644 --- a/natives/reverse.cc +++ b/natives/reverse.cc @@ -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 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; diff --git a/natives/snapchat.cc b/natives/snapchat.cc index 62c997c..b0462df 100644 --- a/natives/snapchat.cc +++ b/natives/snapchat.cc @@ -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 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; diff --git a/natives/speed.cc b/natives/speed.cc index 06d5f52..d751d4b 100644 --- a/natives/speed.cc +++ b/natives/speed.cc @@ -22,16 +22,16 @@ void vipsRemove(Napi::Env *env, Napi::Object *result, Napi::Buffer 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 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; diff --git a/natives/uncaption.cc b/natives/uncaption.cc index 3f29ac9..b890081 100644 --- a/natives/uncaption.cc +++ b/natives/uncaption.cc @@ -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 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)); diff --git a/natives/watermark.cc b/natives/watermark.cc index f4f0e88..ab2f588 100644 --- a/natives/watermark.cc +++ b/natives/watermark.cc @@ -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; diff --git a/natives/whisper.cc b/natives/whisper.cc index 676cffb..54c0a9e 100644 --- a/natives/whisper.cc +++ b/natives/whisper.cc @@ -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 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; diff --git a/natives/zamn.cc b/natives/zamn.cc index 46aac43..80c1940 100644 --- a/natives/zamn.cc +++ b/natives/zamn.cc @@ -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 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); }