Extend meme outline
This commit is contained in:
parent
7a31e063f8
commit
e989901039
1 changed files with 14 additions and 0 deletions
|
@ -32,6 +32,7 @@ Napi::Value Meme(const Napi::CallbackInfo &info) {
|
||||||
int page_height = vips_image_get_page_height(in.get_image());
|
int page_height = vips_image_get_page_height(in.get_image());
|
||||||
int n_pages = vips_image_get_n_pages(in.get_image());
|
int n_pages = vips_image_get_n_pages(in.get_image());
|
||||||
int size = width / 9;
|
int size = width / 9;
|
||||||
|
int dividedWidth = width / 1000;
|
||||||
int rad = 1;
|
int rad = 1;
|
||||||
|
|
||||||
string font_string = (font == "roboto" ? "Roboto Condensed" : font) + " " +
|
string font_string = (font == "roboto" ? "Roboto Condensed" : font) + " " +
|
||||||
|
@ -41,6 +42,13 @@ Napi::Value Meme(const Napi::CallbackInfo &info) {
|
||||||
VImage mask = VImage::black(rad * 2 + 1, rad * 2 + 1) + 128;
|
VImage mask = VImage::black(rad * 2 + 1, rad * 2 + 1) + 128;
|
||||||
mask.draw_circle({255}, rad, rad, rad, VImage::option()->set("fill", true));
|
mask.draw_circle({255}, rad, rad, rad, VImage::option()->set("fill", true));
|
||||||
|
|
||||||
|
VImage altMask;
|
||||||
|
|
||||||
|
if (dividedWidth >= 1) {
|
||||||
|
altMask = VImage::black(dividedWidth * 2 + 1, dividedWidth * 2 + 1) + 128;
|
||||||
|
altMask.draw_circle({255}, dividedWidth, dividedWidth, dividedWidth, VImage::option()->set("fill", true));
|
||||||
|
}
|
||||||
|
|
||||||
VImage topText;
|
VImage topText;
|
||||||
if (top != "") {
|
if (top != "") {
|
||||||
VImage topIn = VImage::text(
|
VImage topIn = VImage::text(
|
||||||
|
@ -57,6 +65,9 @@ Napi::Value Meme(const Napi::CallbackInfo &info) {
|
||||||
VImage topOutline =
|
VImage topOutline =
|
||||||
topIn.morph(mask, VIPS_OPERATION_MORPHOLOGY_DILATE)
|
topIn.morph(mask, VIPS_OPERATION_MORPHOLOGY_DILATE)
|
||||||
.gaussblur(0.5, VImage::option()->set("min_ampl", 0.1));
|
.gaussblur(0.5, VImage::option()->set("min_ampl", 0.1));
|
||||||
|
if (dividedWidth >= 1) {
|
||||||
|
topOutline = topOutline.morph(altMask, VIPS_OPERATION_MORPHOLOGY_DILATE);
|
||||||
|
}
|
||||||
topOutline = (topOutline == (vector<double>){0, 0, 0, 0});
|
topOutline = (topOutline == (vector<double>){0, 0, 0, 0});
|
||||||
VImage topInvert = topOutline.extract_band(3).invert();
|
VImage topInvert = topOutline.extract_band(3).invert();
|
||||||
topOutline = topOutline
|
topOutline = topOutline
|
||||||
|
@ -81,6 +92,9 @@ Napi::Value Meme(const Napi::CallbackInfo &info) {
|
||||||
VImage bottomOutline =
|
VImage bottomOutline =
|
||||||
bottomIn.morph(mask, VIPS_OPERATION_MORPHOLOGY_DILATE)
|
bottomIn.morph(mask, VIPS_OPERATION_MORPHOLOGY_DILATE)
|
||||||
.gaussblur(0.5, VImage::option()->set("min_ampl", 0.1));
|
.gaussblur(0.5, VImage::option()->set("min_ampl", 0.1));
|
||||||
|
if (dividedWidth >= 1) {
|
||||||
|
bottomOutline = bottomOutline.morph(altMask, VIPS_OPERATION_MORPHOLOGY_DILATE);
|
||||||
|
}
|
||||||
bottomOutline = (bottomOutline == (vector<double>){0, 0, 0, 0});
|
bottomOutline = (bottomOutline == (vector<double>){0, 0, 0, 0});
|
||||||
VImage bottomInvert = bottomOutline.extract_band(3).invert();
|
VImage bottomInvert = bottomOutline.extract_band(3).invert();
|
||||||
bottomOutline = bottomOutline
|
bottomOutline = bottomOutline
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue