Fix pixelate bug

This commit is contained in:
Essem 2022-06-22 11:07:40 -05:00
parent ff84306637
commit 3d2a8f23b6
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C

View file

@ -28,8 +28,8 @@ Napi::Value Resize(const Napi::CallbackInfo &info) {
VImage out; VImage out;
int width = in.width(); int width = in.width();
int totalHeight = in.height();
int pageHeight = vips_image_get_page_height(in.get_image()); int pageHeight = vips_image_get_page_height(in.get_image());
int nPages = vips_image_get_n_pages(in.get_image());
int finalHeight; int finalHeight;
if (stretch) { if (stretch) {
@ -41,13 +41,17 @@ Napi::Value Resize(const Napi::CallbackInfo &info) {
out = in.resize(9.5, VImage::option()->set("vscale", 0.5)); out = in.resize(9.5, VImage::option()->set("vscale", 0.5));
finalHeight = pageHeight / 2; finalHeight = pageHeight / 2;
} else { } else {
VImage small = in.resize(0.1); // Pain. Pain. Pain. Pain. Pain.
out = vector<VImage> img;
small.resize((double)width / small.width(), for (int i = 0; i < nPages; i++) {
VImage::option() VImage img_frame =
->set("vscale", (double)totalHeight / small.height()) type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
->set("kernel", VIPS_KERNEL_NEAREST)); VImage resized = img_frame.resize(0.1).resize(
finalHeight = pageHeight; 10, VImage::option()->set("kernel", VIPS_KERNEL_NEAREST));
img.push_back(resized);
finalHeight = resized.height();
}
out = VImage::arrayjoin(img, VImage::option()->set("across", 1));
} }
out.set(VIPS_META_PAGE_HEIGHT, finalHeight); out.set(VIPS_META_PAGE_HEIGHT, finalHeight);