@@ -49,6 +49,16 @@ typedef struct {
4949 double Background [3 ];
5050} WatermarkOptions ;
5151
52+ typedef struct {
53+ int Width ;
54+ int Height ;
55+ int DPI ;
56+ int Top ;
57+ int Left ;
58+ double Background [3 ];
59+ float Opacity ;
60+ } AddTextOptions ;
61+
5262typedef struct {
5363 int Left ;
5464 int Top ;
@@ -451,6 +461,51 @@ vips_watermark(VipsImage *in, VipsImage **out, WatermarkTextOptions *to, Waterma
451461 return 0 ;
452462}
453463
464+ int
465+ vips_add_text (VipsImage * in , VipsImage * * out , WatermarkTextOptions * to , AddTextOptions * o ) {
466+ double ones [3 ] = { 1 , 1 , 1 };
467+
468+ VipsImage * base = vips_image_new ();
469+ VipsImage * * t = (VipsImage * * ) vips_object_local_array (VIPS_OBJECT (base ), 10 );
470+ t [0 ] = in ;
471+
472+ // Make the mask.
473+ if (
474+ vips_text (& t [1 ], to -> Text ,
475+ "width" , o -> Width ,
476+ "dpi" , o -> DPI ,
477+ "font" , to -> Font ,
478+ NULL ) ||
479+ vips_linear1 (t [1 ], & t [2 ], o -> Opacity , 0.0 , NULL ) ||
480+ vips_cast (t [2 ], & t [3 ], VIPS_FORMAT_UCHAR , NULL ) ||
481+ vips_embed (t [3 ], & t [4 ], o -> Left , o -> Top , o -> Width , o -> Height , NULL )
482+ ) {
483+ g_object_unref (base );
484+ return 1 ;
485+ }
486+
487+ // Make the constant image to paint the text with.
488+ if (
489+ vips_black (& t [5 ], 1 , 1 , NULL ) ||
490+ vips_linear (t [5 ], & t [6 ], ones , o -> Background , 3 , NULL ) ||
491+ vips_cast (t [6 ], & t [7 ], VIPS_FORMAT_UCHAR , NULL ) ||
492+ vips_copy (t [7 ], & t [8 ], "interpretation" , t [0 ]-> Type , NULL ) ||
493+ vips_embed (t [8 ], & t [9 ], 0 , 0 , t [0 ]-> Xsize , t [0 ]-> Ysize , "extend" , VIPS_EXTEND_COPY , NULL )
494+ ) {
495+ g_object_unref (base );
496+ return 1 ;
497+ }
498+
499+ // Blend the mask and text and write to output.
500+ if (vips_ifthenelse (t [4 ], t [9 ], t [0 ], out , "blend" , TRUE, NULL )) {
501+ g_object_unref (base );
502+ return 1 ;
503+ }
504+
505+ g_object_unref (base );
506+ return 0 ;
507+ }
508+
454509int
455510vips_gaussblur_bridge (VipsImage * in , VipsImage * * out , double sigma , double min_ampl ) {
456511#if (VIPS_MAJOR_VERSION == 7 && VIPS_MINOR_VERSION < 41 )
0 commit comments