From f1a3387a04a456bfac55b7a8d0f65f048fbff4d4 Mon Sep 17 00:00:00 2001 From: Essem Date: Mon, 4 May 2026 22:50:46 -0500 Subject: [PATCH] fix: Fix uncanny text --- natives/image/uncanny.cc | 61 ++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/natives/image/uncanny.cc b/natives/image/uncanny.cc index 30ed9e2d..7e94b608 100644 --- a/natives/image/uncanny.cc +++ b/natives/image/uncanny.cc @@ -37,35 +37,42 @@ CmdOutput esmb::Image::Uncanny(const string &type, string &outType, const char * string fontResult = findResult != fontPaths.end() ? basePath + findResult->second : ""; LoadFonts(basePath); - VOption *textOptions = VImage::option() - ->set("rgba", true) - ->set("align", VIPS_ALIGN_CENTRE) - ->set("font", font_string.c_str()) - ->set("width", 588) - ->set("height", 90); - if (fontResult != "") { - textOptions = textOptions->set("fontfile", fontResult.c_str()); - } - VImage text = VImage::text(captionText.c_str(), textOptions); - VImage captionImage = - text.extract_band(0, VImage::option()->set("n", 3)) - .gravity(VIPS_COMPASS_DIRECTION_CENTRE, 640, text.height() + 40, VImage::option()->set("extend", "black")); - - VOption *textOptions2 = VImage::option() - ->set("rgba", true) - ->set("align", VIPS_ALIGN_CENTRE) - ->set("font", font_string.c_str()) - ->set("width", 588) - ->set("height", 90); - if (fontResult != "") { - textOptions2 = textOptions2->set("fontfile", fontResult.c_str()); + + if (caption != "") { + VOption *textOptions = VImage::option() + ->set("rgba", true) + ->set("align", VIPS_ALIGN_CENTRE) + ->set("font", font_string.c_str()) + ->set("width", 588) + ->set("height", 90); + if (fontResult != "") { + textOptions = textOptions->set("fontfile", fontResult.c_str()); + } + VImage text = VImage::text(captionText.c_str(), textOptions); + VImage captionImage = + text.extract_band(0, VImage::option()->set("n", 3)) + .gravity(VIPS_COMPASS_DIRECTION_CENTRE, 640, text.height() + 40, VImage::option()->set("extend", "black")); + + base = base.insert(captionImage, 0, 0); } - VImage text2 = VImage::text(caption2Text.c_str(), textOptions2); - VImage caption2Image = - text2.extract_band(0, VImage::option()->set("n", 3)) - .gravity(VIPS_COMPASS_DIRECTION_CENTRE, 640, text.height() + 40, VImage::option()->set("extend", "black")); - base = base.insert(captionImage, 0, 0).insert(caption2Image, 640, 0); + if (caption2 != "") { + VOption *textOptions2 = VImage::option() + ->set("rgba", true) + ->set("align", VIPS_ALIGN_CENTRE) + ->set("font", font_string.c_str()) + ->set("width", 588) + ->set("height", 90); + if (fontResult != "") { + textOptions2 = textOptions2->set("fontfile", fontResult.c_str()); + } + VImage text2 = VImage::text(caption2Text.c_str(), textOptions2); + VImage caption2Image = + text2.extract_band(0, VImage::option()->set("n", 3)) + .gravity(VIPS_COMPASS_DIRECTION_CENTRE, 640, text2.height() + 40, VImage::option()->set("extend", "black")); + + base = base.insert(caption2Image, 640, 0); + } int width = in.width(); int pageHeight = vips_image_get_page_height(in.get_image()); -- 2.51.2